The servers like to log the command line it was invoked with.
It does this by concatenating its arguments, separated by spaces,
into a 150-character buffer on the stack of main(). That's just
wrong. Use a dynamically-allocated buffer instead.
Change-Id: Ibe398e5f449eec176f11f301090a1b68ef13e94b
Reviewed-on: http://gerrit.openafs.org/2275
Tested-by: Derrick Brashear <shadow@dementia.org>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
/* allow super users to manage RX statistics */
rx_SetRxStatUserOk(pr_rxstat_userok);
+ LogCommandLine(argc, argv, "ptserver",
+#if defined(SUPERGROUPS)
+ "1.1",
+#else
+ "1.0",
+#endif
+ "Starting AFS", FSLog);
+
rx_StartServer(1);
osi_audit(PTS_FinishEvent, -1, AUD_END);
exit(0);
extern int OpenLog(const char *fileName);
extern int ReOpenLog(const char *fileName);
extern int LogThreadNum(void);
+extern void LogCommandLine(int argc, char **argv, const char *progname,
+ const char *version, const char *logstring,
+ void (*log) (const char *format, ...));
/* snprintf.c */
#include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
#include <fcntl.h>
#include <afs/stds.h>
+#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include "afsutil.h"
va_end(args);
} /*FSLog */
+void
+LogCommandLine(int argc, char **argv, const char *progname,
+ const char *version, const char *logstring,
+ void (*log) (const char *format, ...))
+{
+ int i, l;
+ char *commandLine, *cx;
+
+ for (l = i = 0; i < argc; i++)
+ l += strlen(argv[i]) + 1;
+ if ((commandLine = malloc(l))) {
+ for (cx = commandLine, i = 0; i < argc; i++) {
+ strcpy(cx, argv[i]);
+ cx += strlen(cx);
+ *(cx++) = ' ';
+ }
+ commandLine[l-1] = '\0';
+ (*log)("%s %s %s%s(%s)\n", logstring, progname,
+ version, strlen(version)>0?" ":"", commandLine);
+ free(commandLine);
+ } else {
+ /* What, we're out of memory already!? */
+ (*log)("%s %s%s%s\n", logstring,
+ progname, strlen(version)>0?" ":"", version);
+ }
+}
+
static void*
DebugOn(void *param)
{
ViceLog(0, ("Both -spare and -pctspare specified, exiting.\n"));
exit(-1);
}
-#ifdef AFS_SGI_XFS_IOPS_ENV
- ViceLog(0, ("XFS/EFS File server starting\n"));
-#else
- ViceLog(0, ("File server starting\n"));
-#endif
+ LogCommandLine(argc, argv, "starting", "", "File server", FSLog);
#if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
/* initialize the pthread soft signal handler thread */
%#endif
/* Current limitations on parameters that affect other packages (i.e. volume) */
+%#define VldbVersion "4"
+
const VLDBVERSION_4 = 4;
const VLDBVERSION = 3;
const OVLDBVERSION = 2;
struct afsconf_cell info;
struct hostent *th;
char hostname[VL_MAXNAMELEN];
- int noAuth = 0, index, i;
- char commandLine[150];
+ int noAuth = 0, index;
char clones[MAXHOSTSPERCELL];
char *auditFileName = NULL;
afs_uint32 host = ntohl(INADDR_ANY);
rx_SetMinProcs(tservice, 2);
rx_SetMaxProcs(tservice, 4);
- for (commandLine[0] = '\0', i = 0; i < argc; i++) {
- if (i > 0)
- strcat(commandLine, " ");
- strcat(commandLine, argv[i]);
- }
- ViceLog(0,
- ("Starting AFS vlserver %d (%s)\n", VLDBVERSION_4, commandLine));
+ LogCommandLine(argc, argv, "vlserver", VldbVersion, "Starting AFS", FSLog);
printf("%s\n", cml_version_number); /* Goes to the log */
/* allow super users to manage RX statistics */
static void * SalvageChildReaperThread(void *);
static int DoSalvageVolume(struct SalvageQueueNode * node, int slot);
-static void SalvageServer(void);
+static void SalvageServer(int argc, char **argv);
static void SalvageClient(VolumeId vid, char * pname);
static int Reap_Child(char * prog, int * pid, int * status);
static void * SalvageLogScanningThread(void *);
static void ScanLogs(struct rx_queue *log_watch_queue);
+struct cmdline_rock {
+ int argc;
+ char **argv;
+};
+
struct log_cleanup_node {
struct rx_queue q;
int pid;
register struct cmd_item *ti;
char pname[100], *temp;
afs_int32 seenpart = 0, seenvol = 0, vid = 0;
+ struct cmdline_rock *rock = (struct cmdline_rock *)arock;
#ifdef AFS_SGI_VNODE_GLUE
if (afs_init_kernel_config(-1) < 0) {
SalvageClient(vid, pname);
} else { /* salvageserver mode */
- SalvageServer();
+ SalvageServer(rock->argc, rock->argv);
}
return (0);
}
pthread_t main_thread;
#endif
-static char commandLine[150];
-
int
main(int argc, char **argv)
{
struct cmd_syndesc *ts;
int err = 0;
-
- int i;
+ struct cmdline_rock arock;
#ifdef AFS_AIX32_ENV
/*
exit(3);
} else {
#endif
- for (commandLine[0] = '\0', i = 0; i < argc; i++) {
- if (i > 0)
- strlcat(commandLine, " ", sizeof(commandLine));
- strlcat(commandLine, argv[i], sizeof(commandLine));
- }
#ifndef AFS_NT40_ENV
if (geteuid() != 0) {
}
#endif
- ts = cmd_CreateSyntax("initcmd", handleit, NULL, "initialize the program");
+ arock.argc = argc;
+ arock.argv = argv;
+
+ ts = cmd_CreateSyntax("initcmd", handleit, &arock, "initialize the program");
cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL,
"Name of partition to salvage");
cmd_AddParm(ts, "-volumeid", CMD_SINGLE, CMD_OPTIONAL,
static int * child_slot;
static void
-SalvageServer(void)
+SalvageServer(int argc, char **argv)
{
int pid, ret;
struct SalvageQueueNode * node;
setlinebuf(logFile);
fprintf(logFile, "%s\n", cml_version_number);
- Log("Starting OpenAFS Online Salvage Server %s (%s)\n", SalvageVersion, commandLine);
-
+ LogCommandLine(argc, argv, "Online Salvage Server",
+ SalvageVersion, "Starting OpenAFS", Log);
/* Get and hold a lock for the duration of the salvage to make sure
* that no other salvage runs at the same time. The routine
* VInitVolumePackage2 (called below) makes sure that a file server or
{
struct cmd_syndesc *ts;
int err = 0;
- char commandLine[150];
- int i;
extern char cml_version_number[];
#ifdef AFS_AIX32_ENV
exit(3);
} else {
#endif
- for (commandLine[0] = '\0', i = 0; i < argc; i++) {
- if (i > 0)
- strcat(commandLine, " ");
- strcat(commandLine, argv[i]);
- }
-
/* All entries to the log will be appended. Useful if there are
* multiple salvagers appending to the log.
*/
/* bad for normal help flag processing, but can do nada */
fprintf(logFile, "%s\n", cml_version_number);
- Log("STARTING AFS SALVAGER %s (%s)\n", SalvageVersion, commandLine);
+ LogCommandLine(argc, argv, "SALVAGER", SalvageVersion, "STARTING AFS",
+ Log);
/* Get and hold a lock for the duration of the salvage to make sure
* that no other salvage runs at the same time. The routine
struct rx_service *service;
struct ktc_encryptionKey tkey;
int rxpackets = 100;
- char commandLine[150];
- int i;
int rxJumbograms = 0; /* default is to send and receive jumbograms. */
int rxMaxMTU = -1;
int bufSize = 0; /* temp variable to read in udp socket buf size */
exit(2);
}
- for (commandLine[0] = '\0', i = 0; i < argc; i++) {
- if (i > 0)
- strcat(commandLine, " ");
- strcat(commandLine, argv[i]);
- }
-
TTsleep = TTrun = 0;
/* parse cmd line */
rx_SetMinProcs(service, 2);
rx_SetMaxProcs(service, 4);
- Log("Starting AFS Volserver %s (%s)\n", VolserVersion, commandLine);
+ LogCommandLine(argc, argv, "Volserver", VolserVersion, "Starting AFS",
+ Log);
if (TTsleep) {
Log("Will sleep %d second%s every %d second%s\n", TTsleep,
(TTsleep > 1) ? "s" : "", TTrun + TTsleep,