From: "Lavrentiev, Anton (NIH/NLM/NCBI) [C]" <lavr@ncbi.nlm.nih.gov>
To: Steve Beck <stevebeck99@hotmail.com>,
"cygwin@cygwin.com" <cygwin@cygwin.com>
Subject: RE: Setting process command name in forked process
Date: Mon, 29 Jan 2024 15:50:50 +0000 [thread overview]
Message-ID: <DM8PR09MB7095D5DD2E88F26054ED5AD6A57E2@DM8PR09MB7095.namprd09.prod.outlook.com> (raw)
In-Reply-To: <DM6PR20MB347644CA2D99E18B0F468578B1792@DM6PR20MB3476.namprd20.prod.outlook.com>
> Can you see what I'm doing wrong?
It used to work in the past, for sure, and was used in some code over here...
Since it was an ad-hoc thing, the behavior might have changed -- I haven't checked it lately.
To make the full disclosure, we reassign the entire __argv here from the linear memory
array made up from new argv[] and argc (s_Argc is the original "argc" passed to main()),
to make all command line to go into argv[0] for the purposes of "ps" output:
extern char** __argv;
extern int __argc;
char* cmdline;
char** x_argv;
size_t len;
int n;
for (len = 0, n = 0; n < argc; ++n)
len += strlen(argv[n]) + 1;
if (!(x_argv = (char**) malloc((s_Argc + 1) * sizeof(*x_argv) + len)))
return 0/*failure*/;
x_argv[0] = cmdline = (char*) x_argv + (s_Argc + 1) * sizeof(*x_argv);
memset(x_argv + 1, 0, s_Argc * sizeof(*x_argv));
for (n = 0; n < argc; ++n) {
if (n)
*cmdline++ = ' ';
len = strlen(argv[n]);
memcpy(cmdline, argv[n], len);
cmdline += len;
}
*cmdline = '\0';
__argv = x_argv;
__argc = 1;
HTH,
Anton Lavrentiev
Contractor NIH/NLM/NCBI
next prev parent reply other threads:[~2024-01-29 15:50 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-23 19:32 Steve Beck
2024-01-24 17:09 ` Brian Inglis
2024-01-26 15:47 ` Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2024-01-26 18:35 ` Steve Beck
2024-01-29 9:58 ` Corinna Vinschen
2024-01-29 22:00 ` Steve Beck
2024-01-30 16:10 ` Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2024-01-29 15:50 ` Lavrentiev, Anton (NIH/NLM/NCBI) [C] [this message]
2024-01-29 15:57 ` Lavrentiev, Anton (NIH/NLM/NCBI) [C]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DM8PR09MB7095D5DD2E88F26054ED5AD6A57E2@DM8PR09MB7095.namprd09.prod.outlook.com \
--to=lavr@ncbi.nlm.nih.gov \
--cc=cygwin@cygwin.com \
--cc=stevebeck99@hotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).