Changing argv
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Changing argv




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Changing argv  
skylazart@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-24-06 06:16 PM

Hi All,

How Can I change the argv?

I know its works:
memset (argv[0], 'A', strlen (argv[0]));

But, When I need a new arg bigger than argv[0] size?

I have to create a new array?

Any ideia?

Thankz in advance






[ Post a follow-up to this message ]



    Re: Changing argv  
ed


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-24-06 06:16 PM

On 24 May 2006 08:22:27 -0700
"skylazart@gmail.com" <skylazart@gmail.com> wrote:

> How Can I change the argv?
>
> I know its works:
> memset (argv[0], 'A', strlen (argv[0]));
>
> But, When I need a new arg bigger than argv[0] size?
>
> I have to create a new array?

I would advise that you do not alter the contents of argv, as you have
already figured out, you should copy it if you make changes.

If you want to alter the size of the memory that you allocate use:

ptr = realloc( my_argv[0], newsize );

--
Regards, Ed                      :: http://www.gnunix.net
proud c++ person
:%s/Open Source/Free Software/g  :: Free DNS available






[ Post a follow-up to this message ]



    Re: Changing argv  
Bjorn Reese


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-25-06 12:18 PM

skylazart@gmail.com wrote:

> How Can I change the argv?
>
> I know its works:
> memset (argv[0], 'A', strlen (argv[0]));
>
> But, When I need a new arg bigger than argv[0] size?
>
> I have to create a new array?

The only portable way I can think of is to create a new array and
then use re-execute the program with this array. Something like this
(disclaimer: the code below may contain defects).

#include <stdlib.h>
#include <string.h>
#include <unistd.h>

static char *faker = "faker";

int main(int argc, char *argv[])
{
int i;
char **array;

if (strcmp(argv[0], faker) != 0) {
/* Build new array */
array = calloc(argc + 1, sizeof(*array));
if (array) {
array[0] = faker;
for (i = 1; i < argc; ++i) {
array[i] = argv[i];
}
execvp(argv[0], array);
}
}

/* Do your normal stuff here */
sleep(60);
return 0;
}

--
mail1dotstofanetdotdk





[ Post a follow-up to this message ]



    Re: Changing argv  
davids@webmaster.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-25-06 12:18 PM

What is your actual problem? Why do you think you need to change argv?

DS






[ Post a follow-up to this message ]



    Re: Changing argv  
skylazart@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-29-06 10:32 PM

I have a multiprocess system. Each one connect into a specific host.

I would like to identify these processes using ps.

Its only for GNU Linux OS.






[ Post a follow-up to this message ]



    Re: Changing argv  
skylazart@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-29-06 10:32 PM

I have found that proftpd change argvs. To identify what user is
connected on these process.
Im trying to understand its implementation.






[ Post a follow-up to this message ]



    Re: Changing argv  
Barry Margolin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-29-06 10:32 PM

In article <1148561544.672773.60660@j55g2000cwa.googlegroups.com>,
"skylazart@gmail.com" <skylazart@gmail.com> wrote:

> I have found that proftpd change argvs. To identify what user is
> connected on these process.
> Im trying to understand its implementation.

Is the source code available?

Another application that changes its argv is sendmail, and I know its
source code is available.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***





[ Post a follow-up to this message ]



    Re: Changing argv  
davids@webmaster.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-29-06 10:32 PM

Aha! Google for 'setproctitle'.

DS






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 10:52 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register