diff --git a/pixelserv.c b/pixelserv.c index 21162e4..2f5a353 100755 --- a/pixelserv.c +++ b/pixelserv.c @@ -68,7 +68,7 @@ void *get_in_addr(struct sockaddr *sa) } #endif -int main (int argc, char *argv[]) // program start +int main (int argc, char* argv[]) // program start { int sockfd = 0; // listen on sock_fd int new_fd = 0; // new connection on new_fd @@ -148,7 +148,7 @@ int main (int argc, char *argv[]) // program start case 'o': errno = 0; select_timeout = strtol(argv[i], NULL, 10); - if (errno) { + if (errno || select_timeout <= 0) { error = 1; } continue; @@ -165,7 +165,13 @@ int main (int argc, char *argv[]) // program start case 'u': user = argv[i]; continue; #endif #ifdef DEBUG - case 'w': warning_time = strtol(argv[i], NULL, 10); continue; + case 'w': + errno = 0; + warning_time = strtol(argv[i], NULL, 10); + if (errno || warning_time <= 0) { + error = 1; + } + continue; #endif //DEBUG default: error = 1; continue; } @@ -219,7 +225,7 @@ int main (int argc, char *argv[]) // program start SET_LINE_NUMBER(__LINE__); openlog("pixelserv", LOG_PID | LOG_CONS | LOG_PERROR, LOG_DAEMON); - version_string = get_version(argv[0]); + version_string = get_version(argc, argv); if (version_string) { syslog(LOG_INFO, "%s", version_string); free(version_string); @@ -549,7 +555,9 @@ int main (int argc, char *argv[]) // program start printf("server: got connection from %s\n", ntop_buf); #endif // call handler function - socket_handler(new_fd + socket_handler(argc + ,argv + ,new_fd ,select_timeout ,pipefd[1] ,stats_url diff --git a/socket_handler.c b/socket_handler.c index 2438ecf..cff12da 100755 --- a/socket_handler.c +++ b/socket_handler.c @@ -387,7 +387,9 @@ void child_signal_handler(int sig) # define TIME_CHECK(x,y...) #endif //DEBUG -void socket_handler(const int new_fd +void socket_handler(int argc + ,char* argv[] + ,const int new_fd ,const time_t select_timeout ,const int pipefd ,const char* const stats_url @@ -522,7 +524,7 @@ void socket_handler(const int new_fd syslog(LOG_ERR, "client did not specify URL for GET request"); } else if (!strcmp(path, stats_url)) { pipedata.status = SEND_STATS; - version_string = get_version(program_name); + version_string = get_version(argc, argv); stat_string = get_stats(1, 0); rsize = asprintf(&aspbuf, "%s%d%s%s%s
%s%s", @@ -538,7 +540,7 @@ void socket_handler(const int new_fd response = aspbuf; } else if (!strcmp(path, stats_text_url)) { pipedata.status = SEND_STATSTEXT; - version_string = get_version(program_name); + version_string = get_version(argc, argv); stat_string = get_stats(0, 1); rsize = asprintf(&aspbuf, "%s%d%s%s\n%s%s", diff --git a/socket_handler.h b/socket_handler.h index 6636f7b..37475b9 100755 --- a/socket_handler.h +++ b/socket_handler.h @@ -33,7 +33,9 @@ typedef struct { double run_time; } response_struct; -void socket_handler(const int new_fd +void socket_handler(int argc + ,char* argv[] + ,const int new_fd ,const time_t select_timeout ,const int pipefd ,const char* const stats_url diff --git a/util.c b/util.c index dd40b38..ec6b864 100755 --- a/util.c +++ b/util.c @@ -42,8 +42,11 @@ volatile sig_atomic_t hed = 0; // private data static struct timespec startup_time = {0, 0}; -char* get_version(const char* const program_name) { +char* get_version(int argc, char* argv[]) { char* retbuf = NULL; + char* optbuf = NULL; + unsigned int optlen = 0, i = 1; + unsigned int arglen[argc]; // capture startup_time if not yet set if (!startup_time.tv_sec) { @@ -53,8 +56,25 @@ char* get_version(const char* const program_name) { } } -// asprintf(&retbuf, "%s version: %s compiled: %s from %s", program_name, VERSION, __DATE__ " " __TIME__, __FILE__); - asprintf(&retbuf, "%s version: %s compiled: %s", program_name, VERSION, __DATE__ " " __TIME__); + // determine total size of all arguments + for (i = 1; i < argc; ++i) + { + arglen[i] = strlen(argv[i]); + optlen += arglen[i]; + } + // allocate a buffer to hold all arguments + optbuf = malloc((optlen * sizeof(char)) + 1); + if (optbuf) { + for (i = 1, optlen = 0; i < argc; ++i) { + strncpy(optbuf + optlen, argv[i], arglen[i]); + optlen += arglen[i]; + } + optbuf[optlen] = '\0'; + asprintf(&retbuf, "%s version: %s compiled: %s options: %s", argv[0], VERSION, __DATE__ " " __TIME__, optbuf); + free(optbuf); + } else { + asprintf(&retbuf, "%s version: %s compiled: %s options: ", argv[0], VERSION, __DATE__ " " __TIME__); + } return retbuf; } diff --git a/util.h b/util.h index 6d718ed..80d7526 100755 --- a/util.h +++ b/util.h @@ -22,7 +22,7 @@ #include // struct timespec, clock_gettime(), difftime() // preprocessor defines -#define VERSION "V35.HZ11WIP13" +#define VERSION "V35.HZ11" #define BACKLOG SOMAXCONN // how many pending connections queue will hold #define CHAR_BUF_SIZE 4095 // surprising how big requests can be with cookies and lengthy yahoo url! @@ -98,7 +98,7 @@ extern volatile sig_atomic_t hed; // generate version string // note that caller is expected to call free() // on the return value when done using it -char* get_version(const char* const program_name); +char* get_version(int argc, char* argv[]); // stats string generator // NOTES: