From 94444ae04c6704714901a7136367782f74f81111 Mon Sep 17 00:00:00 2001 From: Michael Karo Date: Mon, 10 Sep 2018 15:43:16 -0400 Subject: [PATCH] Address errors from gcc 8 with -Wall -Werror --- m4/with_libical.m4 | 45 +- src/cmds/pbs_ds_password.c | 28 +- src/cmds/pbs_release_nodes.c | 3 +- src/cmds/pbsnodes.c | 92 +-- src/cmds/qmgr.c | 31 +- src/cmds/qstat.c | 29 +- src/cmds/qsub.c | 45 +- src/include/hook.h | 5 +- src/include/hook_func.h | 3 +- src/include/libutil.h | 6 +- src/include/log.h | 8 +- src/include/port_forwarding.h | 2 - src/lib/Libattr/attr_fn_time.c | 31 +- src/lib/Libcmds/prepare_path.c | 4 +- src/lib/Libdb/db_postgres_svr.c | 22 +- src/lib/Libifl/enc_ModifyResv.c | 2 - src/lib/Libifl/pbs_loadconf.c | 19 +- src/lib/Liblog/chk_file_sec.c | 54 +- src/lib/Liblog/pbs_log.c | 13 +- src/lib/Libnet/net_server.c | 23 +- src/lib/Libnet/port_forwarding.c | 25 +- src/lib/Libpython/pbs_python_external.c | 87 ++- src/lib/Libpython/pbs_python_svr_internal.c | 24 +- src/lib/Libtpp/tpp_client.c | 129 ++-- src/lib/Libtpp/tpp_router.c | 72 +- src/lib/Libtpp/tpp_transport.c | 60 +- src/lib/Libtpp/tpp_util.c | 6 +- src/lib/Libutil/daemon_protect.c | 5 +- src/lib/Libutil/hook.c | 8 +- src/lib/Libutil/misc_utils.c | 69 +- src/lib/Libutil/pbs_ical.c | 12 +- src/mom_rcp/rcp.c | 21 +- src/mom_rcp/util.c | 4 - src/resmom/catch_child.c | 6 +- src/resmom/linux/mom_mach.c | 8 +- src/resmom/mom_hook_func.c | 66 +- src/resmom/mom_main.c | 26 +- src/resmom/mom_vnode.c | 113 +-- src/resmom/requests.c | 4 +- src/resmom/stage_func.c | 4 +- src/resmom/start_exec.c | 127 ++-- src/scheduler/check.c | 9 +- src/scheduler/fairshare.c | 2 +- src/scheduler/fifo.c | 2 +- src/scheduler/job_info.c | 80 ++- src/scheduler/misc.c | 8 +- src/scheduler/node_info.c | 36 +- src/scheduler/parse.c | 59 +- src/scheduler/pbs_sched.c | 12 +- src/scheduler/resv_info.c | 16 +- src/scheduler/simulate.c | 8 +- src/scheduler/site_code.c | 92 +-- src/server/hook_func.c | 755 ++++++++++---------- src/server/job_func.c | 3 +- src/server/job_recov.c | 22 +- src/server/node_manager.c | 163 +++-- src/server/pbsd_init.c | 30 +- src/server/pbsd_main.c | 39 +- src/server/queue_func.c | 2 +- src/server/req_delete.c | 4 +- src/server/req_modify.c | 13 +- src/server/req_quejob.c | 65 +- src/server/req_register.c | 3 +- src/server/req_runjob.c | 23 +- src/server/svr_jobfunc.c | 140 ++-- src/server/user_func.c | 6 +- src/tools/pbsTclInit.c | 2 +- src/tools/pbs_ds_monitor.c | 5 +- src/tools/pbs_idled.c | 2 +- src/tools/pbs_probe.c | 92 ++- src/tools/pbs_python.c | 107 ++- src/tools/pbs_tclWrap.c | 4 +- src/tools/pbs_upgrade_job.c | 21 +- 73 files changed, 1723 insertions(+), 1443 deletions(-) diff --git a/m4/with_libical.m4 b/m4/with_libical.m4 index 87dddf01758..58a04305b84 100644 --- a/m4/with_libical.m4 +++ b/m4/with_libical.m4 @@ -48,18 +48,26 @@ AC_DEFUN([PBS_AC_WITH_LIBICAL], libical_dir=["/usr"] ) AC_MSG_CHECKING([for libical]) - AS_IF([test -r "$libical_dir/include/ical.h"], - AS_IF([test "$libical_dir" != "/usr"], - [libical_inc="-I$libical_dir/include"]), - AS_IF([test -r "$libical_dir/include/libical/ical.h"], - [libical_inc="-I$libical_dir/include/libical"], - AC_MSG_ERROR([libical headers not found.]))) + AS_IF([test -r "$libical_dir/include/libical/ical.h"], + [libical_include="$libical_dir/include"], + AC_MSG_ERROR([libical headers not found.]) + ) + libical_version=`$SED -n 's/^#define ICAL_VERSION "\([[0-9]]*\)..*/\1/p' "$libical_include/libical/ical.h"` + AS_IF([test "x$libical_version" = "x"], + AC_MSG_ERROR([Could not determine libical version.]) + ) + AS_IF([test $libical_version -gt 1], + AC_DEFINE([LIBICAL_API2], [], [Defined when libical version >= 2]) + ) AS_IF([test "$libical_dir" = "/usr"], - # Using system installed libical + dnl Using system installed libical + libical_inc="" AS_IF([test -r "/usr/lib64/libical.so" -o -r "/usr/lib/libical.so" -o -r "/usr/lib/x86_64-linux-gnu/libical.so"], [libical_lib="-lical"], - AC_MSG_ERROR([libical shared object library not found.])), - # Using developer installed libical + AC_MSG_ERROR([libical shared object library not found.]) + ), + dnl Using developer installed libical + libical_inc="-I$libical_include" AS_IF([test -r "${libical_dir}/lib64/libical.a"], [libical_lib="${libical_dir}/lib64/libical.a"], AS_IF([test -r "${libical_dir}/lib/libical.a"], @@ -72,23 +80,4 @@ AC_DEFUN([PBS_AC_WITH_LIBICAL], AC_SUBST(libical_inc) AC_SUBST(libical_lib) AC_DEFINE([LIBICAL], [], [Defined when libical is available]) - version2_check="yes" - AS_IF([test "x$with_libical" != "x"], - AS_IF([test -r "${libical_dir}/lib/pkgconfig/libical.pc"], - export PKG_CONFIG_PATH=["${libical_dir}/lib/pkgconfig/:$PKG_CONFIG_PATH"], - AS_IF([test -r "${libical_dir}/lib64/pkgconfig/libical.pc"], - export PKG_CONFIG_PATH=["${libical_dir}/lib64/pkgconfig/:$PKG_CONFIG_PATH"], - version2_check="no" - AC_MSG_WARN([libical.pc file not found.]) - ) - ) - ) - AS_IF([test "x$version2_check" = "yes"], - [PKG_CHECK_MODULES([libical_api2], - [libical >= 2], - [AC_DEFINE([LIBICAL_API2], [], [Defined when libical version >= 2])], - [echo "libical version 2 is not available"] - )] - ) ]) - diff --git a/src/cmds/pbs_ds_password.c b/src/cmds/pbs_ds_password.c index 55509552316..f4953143376 100644 --- a/src/cmds/pbs_ds_password.c +++ b/src/cmds/pbs_ds_password.c @@ -116,6 +116,10 @@ #include #endif +#ifndef LOGIN_NAME_MAX +#define LOGIN_NAME_MAX 256 +#endif + int cred_type; size_t cred_len; @@ -254,13 +258,14 @@ read_password(char *passwd) static int gen_password(char *passwd, int len) { - int chrs = 0, c; + int chrs = 0; char allowed_chars[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+"; int arr_len = strlen(allowed_chars); sleep(1); /* sleep 1 second to ensure the srand on time(0) truely randomizes the seed */ srand(time(0)); while (chrs < len) { + int c; c = (char)(rand() % arr_len); passwd[chrs++] = allowed_chars[c]; } @@ -400,12 +405,11 @@ int main(int argc, char *argv[]) { int i, rc; - char passwd[MAX_PASSWORD_LEN+1]; - char passwd2[MAX_PASSWORD_LEN+1]; + char passwd[MAX_PASSWORD_LEN + 1]; + char passwd2[MAX_PASSWORD_LEN + 1]; char *pquoted; - char pwd_file[MAXPATHLEN+1]; - char usr_file[MAXPATHLEN+1]; - char userid[MAXPATHLEN+1]; + char pwd_file[MAXPATHLEN + 1]; + char userid[LOGIN_NAME_MAX + 1]; int fd, errflg = 0; int gen_pwd = 0; char sqlbuff[1024]; @@ -413,7 +417,6 @@ main(int argc, char *argv[]) char *db_errmsg = NULL; int pmode; int change_user = 0; - char datastore[MAXPATHLEN+1]; char *olduser; int update_db = 0; char getopt_format[5]; @@ -619,15 +622,18 @@ main(int argc, char *argv[]) if (change_user == 1) { /* check whether user exists */ - sprintf(sqlbuff, "select usename from pg_user where usename = '%s'", + snprintf(sqlbuff, sizeof(sqlbuff), + "select usename from pg_user where usename = '%s'", userid); if (pbs_db_execute_str(conn, sqlbuff) == 1) { /* now attempt to create new user & set the database passwd to the un-encrypted password */ - sprintf(sqlbuff, "create user \"%s\" SUPERUSER ENCRYPTED PASSWORD '%s'", + snprintf(sqlbuff, sizeof(sqlbuff), + "create user \"%s\" SUPERUSER ENCRYPTED PASSWORD '%s'", userid, pquoted); } else { /* attempt to alter new user & set the database passwd to the un-encrypted password */ - sprintf(sqlbuff, "alter user \"%s\" SUPERUSER ENCRYPTED PASSWORD '%s'", + snprintf(sqlbuff, sizeof(sqlbuff), + "alter user \"%s\" SUPERUSER ENCRYPTED PASSWORD '%s'", userid, pquoted); } memset(passwd, 0, sizeof(passwd)); @@ -698,6 +704,7 @@ main(int argc, char *argv[]) } if (change_user == 1) { + char usr_file[MAXPATHLEN + 1]; #ifdef WIN32 sprintf(usr_file, "%s\\server_priv\\db_user", pbs_conf.pbs_home_path); #else @@ -712,6 +719,7 @@ main(int argc, char *argv[]) } if (update_db == 1 && change_user == 1) { + char datastore[MAXPATHLEN + 1]; #ifndef WIN32 /* ownership is changed only for Unix users * On windows, these files are allways owned by the user who installed the database diff --git a/src/cmds/pbs_release_nodes.c b/src/cmds/pbs_release_nodes.c index 9b8255308ff..58a3492df4d 100644 --- a/src/cmds/pbs_release_nodes.c +++ b/src/cmds/pbs_release_nodes.c @@ -50,11 +50,10 @@ #include /* the master config generated by configure */ #include -const static char ident[] = "@(#) $RCSfile: pbs_release_nodes.c,v $ $Revision: #1 $"; - #define USAGE "usage: pbs_release_nodes [-j job_identifier] host_or_vnode1 host_or_vnode2 ...\n" #define USAGE2 "usage: pbs_release_nodes [-j job_identifier] -a\n" #define USAGE3 " pbs_release_nodes --version\n" + int main(int argc, char **argv, char **envp) /* pbs_release_nodes */ { diff --git a/src/cmds/pbsnodes.c b/src/cmds/pbsnodes.c index ec45833226a..3d5cb9416ef 100644 --- a/src/cmds/pbsnodes.c +++ b/src/cmds/pbsnodes.c @@ -307,14 +307,6 @@ prt_node_summary(char *def_server, struct batch_status *bstatus, int job_summary struct attrl *pattr; struct attrl *next; struct JsonNode *node = NULL; - char *name; - char *state; - char *hardware; - char *queue; - char *os; - char *host; - char *comment; - char *jobs; char suffixletter[] = " kmgtp?"; char *pc; char *pc1; @@ -324,23 +316,11 @@ prt_node_summary(char *def_server, struct batch_status *bstatus, int job_summary char ngpus_info[20] = "0"; char *prev_jobid = NULL; char *cur_jobid = NULL; - int prefix_total = 0; - int prefix_available = 0; /*magnitude of value when printed*/ int prefix_assigned = 0; - int count = 0; long int assigned_mem = 0; - long int available_mem = 0; - long int total_mem = 0; - long int available_cpus = 0; - long int total_cpus = 0; long int njobs = 0; long int run_jobs = 0; long int susp_jobs = 0; - long int total_nmic = 0; - long int available_nmic = 0; - long int total_ngpus = 0; - long int available_ngpus = 0; - long int resource_assigned = 0; long int value = 0; static int done_headers = 0; @@ -359,7 +339,28 @@ prt_node_summary(char *def_server, struct batch_status *bstatus, int job_summary def_server = ""; for (bstat = bstatus; bstat; bstat = bstat->next) { - name = "--"; + char *name; + char *state; + char *hardware; + char *queue; + char *os; + char *host; + char *comment; + char *jobs; + int count; + int prefix_total; + int prefix_available; /* magnitude of value when printed */ + long int total_mem; + long int available_mem; + long int total_cpus; + long int available_cpus; + long int total_nmic; + long int available_nmic; + long int total_ngpus; + long int available_ngpus; + long int resource_assigned; + + name = bstat->name; state = "--"; hardware = "--"; queue = "--"; @@ -367,37 +368,38 @@ prt_node_summary(char *def_server, struct batch_status *bstatus, int job_summary host = "--"; comment = "--"; jobs ="--"; - pc = NULL; - if (job_summary) { - strcpy(mem_info, "0kb/0kb"); - strcpy(ncpus_info, "0/0"); - strcpy(nmic_info, "0/0"); - strcpy(ngpus_info, "0/0"); - } else { - strcpy(mem_info, "0kb"); - strcpy(ncpus_info, "0"); - strcpy(nmic_info, "0"); - strcpy(ngpus_info, "0"); - } + count = 0; prefix_total = 0; prefix_available = 0; - count = 0; - available_mem = 0; total_mem = 0; - available_cpus = 0; + available_mem = 0; total_cpus = 0; - njobs = 0; - run_jobs = 0; - susp_jobs = 0; + available_cpus = 0; total_nmic = 0; available_nmic = 0; total_ngpus = 0; available_ngpus = 0; resource_assigned = 0; + njobs = 0; + run_jobs = 0; + susp_jobs = 0; value = 0; prev_jobid = ""; cur_jobid = ""; - name = bstat->name; + pc = NULL; + + if (job_summary) { + strcpy(mem_info, "0kb/0kb"); + strcpy(ncpus_info, "0/0"); + strcpy(nmic_info, "0/0"); + strcpy(ngpus_info, "0/0"); + } else { + strcpy(mem_info, "0kb"); + strcpy(ncpus_info, "0"); + strcpy(nmic_info, "0"); + strcpy(ngpus_info, "0"); + } + for (pattr = bstat->attribs; pattr; pattr = pattr->next) { if (pattr->resource && (strcmp(pattr->name, "resources_assigned") != 0)) { if ((strcmp(pattr->resource, "mem") == 0)) { @@ -441,10 +443,10 @@ prt_node_summary(char *def_server, struct batch_status *bstatus, int job_summary prefix_total++; } if (job_summary) - snprintf(mem_info, 20, "%ld%cb/%ld%cb", available_mem, suffixletter[prefix_available], + snprintf(mem_info, sizeof(mem_info), "%ld%cb/%ld%cb", available_mem, suffixletter[prefix_available], total_mem, suffixletter[prefix_total]); else - snprintf(mem_info, 20, "%ld%cb", total_mem, suffixletter[prefix_total]); + snprintf(mem_info, sizeof(mem_info), "%ld%cb", total_mem, suffixletter[prefix_total]); } else if ((strcmp(pattr->resource, "ncpus") == 0)) { total_cpus = atol(pattr->value); resource_assigned = 0; @@ -816,7 +818,6 @@ marknode(int con, char *name, char *state2, enum batch_op op2, char *comment) { - char *errmsg; char Comment[80]; struct attropl new[3]; int i; @@ -857,6 +858,8 @@ marknode(int con, char *name, rc = pbs_manager(con, MGR_CMD_SET, MGR_OBJ_HOST, name, new, NULL); if (rc && !quiet) { + char *errmsg; + fprintf(stderr, "Error marking node %s - ", name); if ((errmsg = pbs_geterrmsg(con)) != NULL) fprintf(stderr, "%s\n", errmsg); @@ -901,7 +904,6 @@ main(int argc, char *argv[]) int long_summary = 0; int format = 0; int prt_summary = 0; - int matched = 0; /*test for real deal or just version and exit*/ @@ -1283,6 +1285,8 @@ main(int argc, char *argv[]) /*list nodes and vnodes associated with them.*/ if (argc-optind) { for (bstat = bstat_head; bstat;bstat = bstat->next) { + int matched; + matched = 0; pa = argv+optind; while (*pa) { diff --git a/src/cmds/qmgr.c b/src/cmds/qmgr.c index deebc233ca9..9395c733e3c 100644 --- a/src/cmds/qmgr.c +++ b/src/cmds/qmgr.c @@ -136,7 +136,7 @@ static char prompt[]="Qmgr: "; /* Prompt if input is from terminal */ static char contin[]="Qmgr< "; /* Prompt if input is continued across lines */ char *cur_prompt = prompt; -char hook_tempfile_errmsg[HOOK_BUF_SIZE] = { '\0' }; +static char hook_tempfile_errmsg[HOOK_MSG_SIZE] = {'\0'}; /* * This variable represents the use of the -z option on the command line. @@ -176,8 +176,8 @@ static char *entlim_attrs[] = { /* Hook-related variables and functions */ -char hook_tempfile[MAXPATHLEN+1]; /* a temporary file in PBS_HOOK_WORKDIR */ -char hook_tempdir[MAXPATHLEN+1]; /* PBS_HOOK_WORKDIR path */ +static char *hook_tempfile = NULL; /* a temporary file in PBS_HOOK_WORKDIR */ +static char *hook_tempdir = NULL; /* PBS_HOOK_WORKDIR path */ /** * @brief @@ -1210,27 +1210,27 @@ main(int argc, char **argv) (sizeof(conf_full_server_name) - 1)); } - memset(hook_tempdir, '\0', MAXPATHLEN+1); - snprintf(hook_tempdir, MAXPATHLEN, "%s/server_priv/%s", + pbs_asprintf(&hook_tempdir, "%s/server_priv/%s", pbs_conf.pbs_home_path, PBS_HOOK_WORKDIR); - memset(hook_tempfile, '\0', MAXPATHLEN+1); - snprintf(hook_tempfile, MAXPATHLEN, "%s/qmgr_hook%dXXXXXX", + pbs_asprintf(&hook_tempfile, "%s/qmgr_hook%dXXXXXX", hook_tempdir, getpid()); #ifdef WIN32 /* mktemp() generates a filename */ if (mktemp(hook_tempfile) == NULL) { - snprintf(hook_tempfile_errmsg, HOOK_BUF_SIZE-1, + snprintf(hook_tempfile_errmsg, sizeof(hook_tempfile_errmsg), "unable to generate a hook_tempfile from %s - %s\n", hook_tempfile, strerror(errno)); hook_tempfile[0] = '\0'; /* hook_tempfile name generation not successful */ } #else - /* For Linux/Unix, it is recommended to use mkstemp() for mktemp() is */ - /* dangerous - see mktemp(3). */ - /* mkstemp() generates and CREATES a filename */ - if ((htmp_fd=mkstemp(hook_tempfile)) == -1) { - snprintf(hook_tempfile_errmsg, HOOK_BUF_SIZE-1, + /* + * For Linux/Unix, it is recommended to use mkstemp() for mktemp() is + * dangerous - see mktemp(3). + * mkstemp() generates and CREATES a filename + */ + if ((htmp_fd = mkstemp(hook_tempfile)) == -1) { + snprintf(hook_tempfile_errmsg, sizeof(hook_tempfile_errmsg), "unable to generate a hook_tempfile from %s - %s\n", hook_tempfile, strerror(errno)); hook_tempfile[0] = '\0'; /* hook_tempfile name generation not successful */ @@ -1303,8 +1303,7 @@ main(int argc, char **argv) name = NULL; } } - } - else { + } else { if (eopt) printf("%s\n", copt); @@ -1785,6 +1784,8 @@ clean_up_and_exit(int exit_val) { struct server *cur_svr, *next_svr; + free(hook_tempdir); + free(hook_tempfile); free_objname_list(active_servers); free_objname_list(active_queues); free_objname_list(active_nodes); diff --git a/src/cmds/qstat.c b/src/cmds/qstat.c index 04006bf2c00..2c7eac36c80 100644 --- a/src/cmds/qstat.c +++ b/src/cmds/qstat.c @@ -833,7 +833,7 @@ altdsp_statjob(struct batch_status *pstat, struct batch_status *prtheader, int a tasks = pat->value; } else if (strcmp(pat->resource, "mem") == 0) { (void)strncpy(rqmem, - cnv_size(pat->value, alt_opt), SIZEL); + cnv_size(pat->value, alt_opt), sizeof(rqmem) - 1); } else if (strcmp(pat->resource, "walltime") == 0) { rqtimewal = pat->value; } else if (strcmp(pat->resource, "cput") == 0) { @@ -841,13 +841,13 @@ altdsp_statjob(struct batch_status *pstat, struct batch_status *prtheader, int a usecput = 1; } else if (strcmp(pat->resource, "srfs_big") == 0) { (void)strncpy(srfsbig, - cnv_size(pat->value, alt_opt), SIZEL-1); + cnv_size(pat->value, alt_opt), sizeof(srfsbig) - 1); } else if (strcmp(pat->resource, "srfs_fast") == 0) { (void)strncpy(srfsfast, - cnv_size(pat->value, alt_opt), SIZEL-1); + cnv_size(pat->value, alt_opt), sizeof(srfsfast) - 1); } else if (strcmp(pat->resource, "piofs") == 0) { (void)strncpy(pfs, - cnv_size(pat->value, alt_opt), SIZEL-1); + cnv_size(pat->value, alt_opt), sizeof(pfs) - 1); } } else if (strcmp(pat->name, ATTR_exechost) == 0) { @@ -996,7 +996,7 @@ altdsp_statque(char *serv, struct batch_status *pstat, int opt) while (pstat) { /* *rmem = '\0'; */ - (void)strncpy(rmem, "-- ", SIZEL-1); + (void)strncpy(rmem, "-- ", sizeof(rmem) - 1); cput = blank; wallt = blank; nodect= "-- "; @@ -1025,7 +1025,7 @@ altdsp_statque(char *serv, struct batch_status *pstat, int opt) } else if (strcmp(pat->name, ATTR_rescmax) == 0) { if (strcmp(pat->resource, "mem") == 0) { (void)strncpy(rmem, - cnv_size(pat->value, opt), SIZEL); + cnv_size(pat->value, opt), sizeof(rmem) - 1); } else if (strcmp(pat->resource, "cput") == 0) { cput = pat->value; } else if (strcmp(pat->resource, "walltime")==0) { @@ -1104,11 +1104,9 @@ percent_cal(char *state, char *timeu, char *timer, char *wtimu, char *wtimr, cha static char rtn[TIMEUL+1]; long bot = 0; long top = 0; - long perccpu = -1; - long percwal = -1; - int qu, ru, ex, ep; + int qu, ru, ex, ep; - strcpy(rtn, "-- "); + snprintf(rtn, sizeof(rtn), "-- "); switch (*state) { @@ -1123,23 +1121,28 @@ percent_cal(char *state, char *timeu, char *timer, char *wtimu, char *wtimr, cha if (arsct) { /* array job: percent expired */ + long percexp = -1; sscanf(arsct, "Queued:%d Running:%d Exiting:%d Expired:%d", &qu, &ru, &ex, &ep); bot = qu + ru + ex + ep; top = ep; if (bot != 0) - sprintf(rtn, "%3ld ", (top * 100)/bot); + percexp = (top * 100) / bot; + if ((percexp >= 0) && (percexp < 1000)) + sprintf(rtn, "%3ld ", percexp); } else { + long perccpu = -1; + long percwal = -1; if (timer && timeu) { /* if cput specified */ top = cvt_time_to_seconds(timeu); bot = cvt_time_to_seconds(timer); if (bot != 0) - perccpu = (top * 100)/bot; + perccpu = (top * 100) / bot; } if (wtimr && wtimu) { /* if walltime specified */ top = cvt_time_to_seconds(wtimu); bot = cvt_time_to_seconds(wtimr); if (bot != 0) - percwal = (top * 100)/bot; + percwal = (top * 100) / bot; } if ((perccpu != -1) || (percwal != -1)) { sprintf(rtn, "%3ld ", diff --git a/src/cmds/qsub.c b/src/cmds/qsub.c index e0d6718952a..6be895b0f66 100644 --- a/src/cmds/qsub.c +++ b/src/cmds/qsub.c @@ -224,8 +224,12 @@ static char server_out[PBS_MAXSERVERNAME + PBS_MAXPORTNUM + 2]; /* Destination s static struct batch_status *ss = NULL; static char *dfltqsubargs = NULL; /* Default qsub arguments */ static int sd_svr; /* return from pbs_connect */ -static char script_tmp[MAXPATHLEN + 1] = ""; /* name of script file copy */ -static char fl[2 * MAXPATHLEN + 1]; /* the filename used as the pipe name */ +static char script_tmp[MAXPATHLEN + 1] = {'\0'}; /* name of script file copy */ +#ifdef WIN32 +static char fl[(2 * MAXPATHLEN) + 1] = {'\0'}; /* the filename used as the pipe name */ +#else +static char fl[sizeof(((struct sockaddr_un *)0)->sun_path)] = {'\0'}; /* the filename used as the pipe name */ +#endif #define BUFSIZE 1024 /* windows default pipe buffer size */ #define PIPE_TIMEOUT 0 /* default windows pipe timeout */ static char *pbs_hostvar = NULL; /* buffer containing ",PBS_O_HOST=" and host name */ @@ -3598,9 +3602,9 @@ get_script(FILE *file, char *script, char *prefix) #ifdef WIN32 - _snprintf(tmp_name, MAXPATHLEN, "%s\\%s", tmpdir, tmp_template); + _snprintf(tmp_name, sizeof(tmp_name), "%s\\%s", tmpdir, tmp_template); if ((in = _mktemp(tmp_name)) != NULL) { - snprintf(script, MAXPATHLEN, "%s", tmp_name); + snprintf(script, MAXPATHLEN + 1, "%s", tmp_name); if ((TMP_FILE = fopen(in, "w+")) == NULL) err = 1; } else { @@ -3609,10 +3613,10 @@ get_script(FILE *file, char *script, char *prefix) #else /* not windows */ - snprintf(tmp_name, MAXPATHLEN, "%s/%s", tmpdir, tmp_template); + snprintf(tmp_name, sizeof(tmp_name), "%s/%s", tmpdir, tmp_template); fds = mkstemp(tmp_name); /* returns file descriptor */ if (fds != -1) { - snprintf(script, MAXPATHLEN, "%s", tmp_name); + snprintf(script, MAXPATHLEN + 1, "%s", tmp_name); if ((TMP_FILE = fdopen(fds, "w+")) == NULL) err = 1; } else { @@ -5310,7 +5314,7 @@ do_submit2(char *rmsg) * Get the filename to be used for communications. This is created by * appending the target server name and the user login name to a filename. * - * @param[out] fl - The filename used for the communication pipe/socket for + * @param[out] fname - The filename used for the communication pipe/socket for * the communication between background and forground * qsub processes. * @@ -5318,12 +5322,12 @@ do_submit2(char *rmsg) * */ static void -get_comm_filename(char *fl) +get_comm_filename(char *fname) { char *env_svr = getenv(PBS_CONF_SERVER_NAME); char *env_port = getenv(PBS_CONF_BATCH_SERVICE_PORT); - sprintf(fl, "\\\\.\\pipe\\pipe_%s_%s_%s_%s_%s_%s", + sprintf(fname, "\\\\.\\pipe\\pipe_%s_%s_%s_%s_%s_%s", ((server_out == NULL || server_out[0] == 0)? "default" : server_out), getlogin(), @@ -5349,7 +5353,7 @@ get_comm_filename(char *fl) * and results in the background qsub process to quit silently. * * - * @param[in] fl - The filename used for the communication pipe/socket for + * @param[in] fname - The filename used for the communication pipe/socket for * the communication between background and forground * qsub processes. * @param[in] handle - Handle to synchronization event between foreground and @@ -5358,7 +5362,7 @@ get_comm_filename(char *fl) * */ static void -do_daemon_stuff(char *file, char *handle, char *server) +do_daemon_stuff(char *fname, char *handle, char *server) { HANDLE h_pipe; int rc, pipe_rc; @@ -5388,7 +5392,7 @@ do_daemon_stuff(char *file, char *handle, char *server) goto error; o_overlap.hEvent = h_event; - h_pipe = CreateNamedPipe(file, + h_pipe = CreateNamedPipe(fname, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, @@ -5675,19 +5679,20 @@ daemon_submit(char *qsub_exe, int *do_regular_submit) * @brief * Sets the filename to be used for the unix domain socket based comm. * This is formed by appending the UID and the target server name to the - * filename. + * filename. The length of the string is restricted to the length of the + * global variable fl. This is fairly small (108 characters) for Linux. * - * @param[out] fl - The filename in tmpdir that is used as the unix domain socket + * @param[out] fname - The filename in tmpdir that is used as the unix domain socket * file. * */ static void -get_comm_filename(char *fl) +get_comm_filename(char *fname) { char *env_svr = getenv(PBS_CONF_SERVER_NAME); char *env_port = getenv(PBS_CONF_BATCH_SERVICE_PORT); - sprintf(fl, "%s/pbs_%s_%lu_%s_%s_%s_%s", + sprintf(fname, "%s/pbs_%.16s_%lu_%.8s_%.32s_%.16s_%.5s", tmpdir, ((server_out == NULL || server_out[0] == 0) ? "default" : server_out), @@ -5704,7 +5709,7 @@ get_comm_filename(char *fl) * Check whether a unix domain socket file is available. * That is an indication that a background qsub might already be running. * - * @param[out] fl - The filename used for the communication pipe/socket for + * @param[out] fname - The filename used for the communication pipe/socket for * the communication between background and forground * qsub processes. * @@ -5714,10 +5719,10 @@ get_comm_filename(char *fl) * */ static int -check_qsub_daemon(char *fl) +check_qsub_daemon(char *fname) { - get_comm_filename(fl); - if (access(fl, F_OK) == 0) { + get_comm_filename(fname); + if (access(fname, F_OK) == 0) { /* check if file is usable */ return 1; } diff --git a/src/include/hook.h b/src/include/hook.h index 5def35c9513..8f753e8e279 100644 --- a/src/include/hook.h +++ b/src/include/hook.h @@ -155,9 +155,10 @@ typedef struct hook hook; #define HOOK_TRACKING_SUFFIX ".TR" /* hook pending action tracking file */ #define HOOK_BAD_SUFFIX ".BD" /* a bad (moved out of the way) hook file */ #define HOOK_CONFIG_SUFFIX ".CF" -#define PBS_HOOKDIR "hooks" -#define PBS_HOOK_WORKDIR PBS_HOOKDIR "/tmp" +#define PBS_HOOKDIR "hooks" +#define PBS_HOOK_WORKDIR PBS_HOOKDIR "/tmp" #define PBS_HOOK_TRACKING PBS_HOOKDIR "/tracking" +#define PBS_HOOK_NAME_SIZE 512 /* Some hook-related buffer sizes */ #define HOOK_BUF_SIZE 512 diff --git a/src/include/hook_func.h b/src/include/hook_func.h index 2d234874eb8..b654c44b724 100644 --- a/src/include/hook_func.h +++ b/src/include/hook_func.h @@ -43,6 +43,7 @@ extern "C" { #include "work_task.h" #include "job.h" +#include "hook.h" /* * hook_func.h - structure definitions for hook objects @@ -66,7 +67,7 @@ extern "C" { #define MOM_HOOK_SEND_ACTIONS (MOM_HOOK_ACTION_SEND_ATTRS | MOM_HOOK_ACTION_SEND_SCRIPT | MOM_HOOK_ACTION_SEND_CONFIG) struct mom_hook_action { - char hookname[MAXPATHLEN+1]; + char hookname[PBS_HOOK_NAME_SIZE]; unsigned int action; int do_delete_action_first; /* force order between delete and send actions */ long long int tid; /* transaction id to group actions under */ diff --git a/src/include/libutil.h b/src/include/libutil.h index 9093cfe0620..e7f5362cf4c 100644 --- a/src/include/libutil.h +++ b/src/include/libutil.h @@ -193,6 +193,11 @@ char *pbs_strcat(char **strbuf, int *ssize, char *str); char *pbs_fgets(char **pbuf, int *pbuf_size, FILE *fp); char *pbs_fgets_extend(char **pbuf, int *pbuf_size, FILE *fp); +/* + * Internal asprintf() implementation for use on all platforms + */ +int pbs_asprintf(char **dest, const char *fmt, ...); + /* * calculate the number of digits to the right of the decimal point in * a floating point number. This can be used in conjunction with @@ -272,7 +277,6 @@ char * escape_delimiter(char *str, char *delim, char esc); */ void convert_duration_to_str(time_t duration, char* buf, int bufsize); - #ifdef __cplusplus } #endif diff --git a/src/include/log.h b/src/include/log.h index 857fd528e31..57608157a46 100644 --- a/src/include/log.h +++ b/src/include/log.h @@ -59,7 +59,13 @@ * include file for error/event logging */ -#define LOG_BUF_SIZE 4096 +/* + * The default log buffer size should be large enough to hold a short message + * together with the full pathname of a file. A full pathname may be up to 4096 + * characters. Add to this an extra 256 characters. This helps to avoid format + * truncation warnings from certain compilers. + */ +#define LOG_BUF_SIZE 4352 /* The following macro assist in sharing code between the Server and Mom */ #define LOG_EVENT log_event diff --git a/src/include/port_forwarding.h b/src/include/port_forwarding.h index f099eb43c59..7353cc06745 100644 --- a/src/include/port_forwarding.h +++ b/src/include/port_forwarding.h @@ -45,8 +45,6 @@ extern "C" { /* Max size of buffer to store data*/ #define PF_BUF_SIZE 8192 -#define LOG_BUF_SIZE 4096 - /* Limits the number of simultaneous X applications that a single job can run in the background to 24 . 1 socket fd is used for storing the X11 listening socket fd and 2 socket fds are used whenever an diff --git a/src/lib/Libattr/attr_fn_time.c b/src/lib/Libattr/attr_fn_time.c index a3d5efb18f2..228d8c1e35a 100644 --- a/src/lib/Libattr/attr_fn_time.c +++ b/src/lib/Libattr/attr_fn_time.c @@ -171,7 +171,7 @@ decode_time(struct attribute *patr, char *name, char *rescn, char *val) /** * @brief * encode_time - encode attribute of type long into attr_extern - * with value in form of [[hh:]mm:]ss + * with value in form of hh:mm:ss * * @param[in] attr - ptr to attribute to encode * @param[in] phead - ptr to head of attrlist list @@ -188,34 +188,35 @@ decode_time(struct attribute *patr, char *name, char *rescn, char *val) */ /*ARGSUSED*/ -#define CVNBUFSZ 21 +#define CVNBUFSZ 24 int encode_time(attribute *attr, pbs_list_head *phead, char *atname, char *rsname, int mode, svrattrl **rtnl) { - size_t ct; - char cvnbuf[CVNBUFSZ]; - long hr; - int min; - long n; + size_t ct; + unsigned long n; + unsigned long hr; + unsigned int min; + unsigned int sec; svrattrl *pal; - int sec; - char *pv; + char *pv; + char cvnbuf[CVNBUFSZ] = {'\0'}; if (!attr) return (-1); if (!(attr->at_flags & ATR_VFLAG_SET)) return (0); + if (attr->at_val.at_long < 0) + return (-1); - n = attr->at_val.at_long; - hr = n / 3600; - n = n % 3600; + n = attr->at_val.at_long; + hr = n / 3600; + n %= 3600; min = n / 60; - n = n % 60; - sec = n; + sec = n % 60; pv = cvnbuf; - (void)sprintf(pv, "%02ld:%02d:%02d", hr, min, sec); + (void)sprintf(pv, "%02lu:%02u:%02u", hr, min, sec); pv += strlen(pv); ct = strlen(cvnbuf) + 1; diff --git a/src/lib/Libcmds/prepare_path.c b/src/lib/Libcmds/prepare_path.c index b123ca29713..9b486dffc71 100644 --- a/src/lib/Libcmds/prepare_path.c +++ b/src/lib/Libcmds/prepare_path.c @@ -281,7 +281,7 @@ prepare_path(char *path_in, char *path_out) } else #endif { - strncat(path_out, cwd, MAXPATHLEN - strlen(path_out)); + strncat(path_out, cwd, (MAXPATHLEN + 1) - strlen(path_out)); if (strlen(path_out) < MAXPATHLEN) strcat(path_out, "/"); } @@ -334,7 +334,7 @@ prepare_path(char *path_in, char *path_out) strcpy(path_out, replace_space(path_out, "\\ ")); path_out[MAXPATHLEN - 1] = '\0'; #else - strncat(path_out, path_name, MAXPATHLEN - strlen(path_out)); + strncat(path_out, path_name, (MAXPATHLEN + 1) - strlen(path_out)); #endif return (0); diff --git a/src/lib/Libdb/db_postgres_svr.c b/src/lib/Libdb/db_postgres_svr.c index 04937aa8f61..f0dfdbc489a 100644 --- a/src/lib/Libdb/db_postgres_svr.c +++ b/src/lib/Libdb/db_postgres_svr.c @@ -343,28 +343,30 @@ pbs_db_get_schema_version(pbs_db_conn_t *conn, int *db_maj_ver, int *db_min_ver) { PGresult *res; int rc; - char ver_str[MAX_SCHEMA_VERSION_LEN+1]; + char ver_str[MAX_SCHEMA_VERSION_LEN + 1] = {'\0'}; char *token; + char *val; if ((rc = pg_db_query(conn, STMT_SELECT_DBVER, 0, &res)) != 0) return rc; - memset(ver_str, 0, sizeof(ver_str)); - strncpy(ver_str, PQgetvalue(res, 0, PQfnumber(res, "pbs_schema_version")), MAX_SCHEMA_VERSION_LEN+1); - if (ver_str[MAX_SCHEMA_VERSION_LEN] != '\0') + val = PQgetvalue(res, 0, PQfnumber(res, "pbs_schema_version")); + if (!val) return -1; + if (*val == '\0') + return -1; + + snprintf(ver_str, sizeof(ver_str), "%s", val); token = strtok(ver_str, "."); - if (token) - *db_maj_ver = atol(token); - else + if (!token) return -1; + *db_maj_ver = atol(token); token = strtok(NULL, "."); - if (token) - *db_min_ver = atol(token); - else + if (!token) return -1; + *db_min_ver = atol(token); return 0; } diff --git a/src/lib/Libifl/enc_ModifyResv.c b/src/lib/Libifl/enc_ModifyResv.c index 23a735409e1..a1a7209128a 100644 --- a/src/lib/Libifl/enc_ModifyResv.c +++ b/src/lib/Libifl/enc_ModifyResv.c @@ -36,8 +36,6 @@ * */ -const static char ident[] = "@(#) $RCSfile: enc_ModifyResv.c,v $ $Revision: #9 $"; - #include /* the master config generated by configure */ #include "libpbs.h" diff --git a/src/lib/Libifl/pbs_loadconf.c b/src/lib/Libifl/pbs_loadconf.c index d4f2fb954b5..7340e4a6520 100644 --- a/src/lib/Libifl/pbs_loadconf.c +++ b/src/lib/Libifl/pbs_loadconf.c @@ -213,13 +213,14 @@ parse_config_line(FILE *fp, char **key, char **val) char *end; char *split; char *ret; - int len; *key = '\0'; *val = '\0'; /* Use a do-while rather than a goto. */ do { + int len; + ret = pbs_fgets(&pbs_loadconf_buf, &pbs_loadconf_len, fp); if (ret == NULL) break; @@ -819,11 +820,17 @@ pbs_loadconf(int reload) buf[0] = '\0'; if (pbs_conf.pbs_home_path == NULL) - sprintf(buf, "%s %s", buf, PBS_CONF_HOME); - if (pbs_conf.pbs_exec_path == NULL) - sprintf(buf, "%s %s", buf, PBS_CONF_EXEC); - if (pbs_conf.pbs_server_name == NULL) - sprintf(buf, "%s %s", buf, PBS_CONF_SERVER_NAME); + strcat(buf, PBS_CONF_HOME); + if (pbs_conf.pbs_exec_path == NULL) { + if (buf[0] != '\0') + strcat(buf, " "); + strcat(buf, PBS_CONF_EXEC); + } + if (pbs_conf.pbs_server_name == NULL) { + if (buf[0] != '\0') + strcat(buf, " "); + strcat(buf, PBS_CONF_SERVER_NAME); + } if (buf[0] != '\0') { fprintf(stderr, "pbsconf error: pbs conf variables not found: %s\n", buf); goto err; diff --git a/src/lib/Liblog/chk_file_sec.c b/src/lib/Liblog/chk_file_sec.c index 5f322729622..50678a92122 100644 --- a/src/lib/Liblog/chk_file_sec.c +++ b/src/lib/Liblog/chk_file_sec.c @@ -51,20 +51,14 @@ #include #include "portability.h" #include "log.h" +#include "libutil.h" +#include "pbs_ifl.h" #ifndef S_ISLNK #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) #endif -#ifndef MAXPATHLEN -#ifdef PATHSIZE -#define MAXPATHLEN PATHSIZE -#else -#define MAXPATHLEN 1024 -#endif /* PATHSIZE */ -#endif /* MAXPATHLEN */ - #ifdef WIN32 /** @@ -317,23 +311,17 @@ chk_file_sec(char *path, int isdir, int sticky, int disallow, int fullpath) chkerr: if (rc != 0) { - char *error_buf; - - if ((error_buf = malloc(1024)) == 0) { - log_err(rc, "chk_file_sec", "Malloc failed"); - } else { - sprintf(error_buf, - "Security violation \"%s\" resolves to \"%s\"", - path, real); - log_err(rc, "chk_file_sec", error_buf); + char *error_buf; + pbs_asprintf(&error_buf, + "Security violation \"%s\" resolves to \"%s\"", + path, real); + log_err(rc, __func__, error_buf); #ifdef WIN32 - if (strlen(log_buffer) > 0) { - log_err(rc, "chk_file_sec", log_buffer); - } + if (strlen(log_buffer) > 0) + log_err(rc, __func__, log_buffer); #endif - free(error_buf); - } + free(error_buf); } free(real); @@ -448,23 +436,17 @@ tmp_file_sec(char *path, int isdir, int sticky, int disallow, int fullpath) chkerr: if (rc != 0) { - char *error_buf; - - if ((error_buf = malloc(1024)) == NULL) { - log_err(rc, "chk_file_sec", "Malloc failed"); - } else { - sprintf(error_buf, - "Security violation \"%s\" resolves to \"%s\"", - path, real); - log_err(rc, "chk_file_sec", error_buf); + char *error_buf; + pbs_asprintf(&error_buf, + "Security violation \"%s\" resolves to \"%s\"", + path, real); + log_err(rc, __func__, error_buf); #ifdef WIN32 - if (strlen(log_buffer) > 0) { - log_err(rc, "chk_file_sec", log_buffer); - } + if (strlen(log_buffer) > 0) + log_err(rc, __func__, log_buffer); #endif - free(error_buf); - } + free(error_buf); } free(real); diff --git a/src/lib/Liblog/pbs_log.c b/src/lib/Liblog/pbs_log.c index 824418414cc..79ebaf1baae 100644 --- a/src/lib/Liblog/pbs_log.c +++ b/src/lib/Liblog/pbs_log.c @@ -454,13 +454,14 @@ log_add_if_info() char msg[LOG_BUF_SIZE]; char temp[LOG_BUF_SIZE]; int i; - char dest[LOG_BUF_SIZE]; + char dest[LOG_BUF_SIZE * 2]; struct log_net_info *ni, *curr; memset(msg, '\0', sizeof(msg)); ni = get_if_info(msg); - if(strlen(msg)){ /* Adding error message to log */ - strncpy(tbuf, msg, LOG_BUF_SIZE); + if (msg[0] != '\0') { + /* Adding error message to log */ + snprintf(tbuf, sizeof(tbuf), "%s", msg); log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, LOG_INFO, msg_daemonname, tbuf); } if (!ni) @@ -468,12 +469,12 @@ log_add_if_info() /* Add info to log */ for (curr = ni; curr; curr = curr->next) { - snprintf(tbuf, LOG_BUF_SIZE, "%s interface %s: ", + snprintf(tbuf, sizeof(tbuf), "%s interface %s: ", (curr->iffamily) ? curr->iffamily : "NULL", (curr->ifname) ? curr->ifname : "NULL"); for (i = 0; curr->ifhostnames[i]; i++) { - snprintf(temp, LOG_BUF_SIZE, "%s ", curr->ifhostnames[i]); - snprintf(dest, LOG_BUF_SIZE, "%s%s", tbuf, temp); + snprintf(temp, sizeof(temp), "%s ", curr->ifhostnames[i]); + snprintf(dest, sizeof(dest), "%s%s", tbuf, temp); } log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, LOG_INFO, msg_daemonname, dest); } diff --git a/src/lib/Libnet/net_server.c b/src/lib/Libnet/net_server.c index 073f091b055..29b13caedff 100644 --- a/src/lib/Libnet/net_server.c +++ b/src/lib/Libnet/net_server.c @@ -439,9 +439,10 @@ connection_idlecheck(void) static int engage_authentication(conn_t *pconn) { - int ret; - int sd; - char ebuf[ PBS_MAXHOSTNAME + 1 ]; + int ret; + int sd; + char ebuf[PBS_MAXHOSTNAME + 1] = {'\0'}; + char *msgbuf; if (pconn == NULL || (sd = pconn->cn_sock) <0) { log_err(-1, __func__, "bad arguments, unable to authenticate"); @@ -462,9 +463,11 @@ engage_authentication(conn_t *pconn) (void)get_connecthost(sd, ebuf, sizeof(ebuf)); - sprintf(logbuf, "unable to authenticate connection from (%s:%d)", + pbs_asprintf(&msgbuf, + "unable to authenticate connection from (%s:%d)", ebuf, pconn->cn_port); - log_err(-1, __func__ , logbuf); + log_err(-1, __func__ , msgbuf); + free(msgbuf); return (-1); } @@ -793,15 +796,15 @@ close_conn(int sd) if (svr_conn[idx]->cn_active != ChildPipe) { if (CS_close_socket(sd) != CS_SUCCESS) { - - char ebuf[ PBS_MAXHOSTNAME + 1 ] = {'\0'}; + char ebuf[PBS_MAXHOSTNAME + 1] = {'\0'}; + char *msgbuf; (void)get_connecthost(sd, ebuf, sizeof(ebuf)); - snprintf(logbuf,sizeof(logbuf), + pbs_asprintf(&msgbuf, "problem closing security context for %s:%d", ebuf, svr_conn[idx]->cn_port); - - log_err(-1, __func__ , logbuf); + log_err(-1, __func__ , msgbuf); + free(msgbuf); } /* if there is a function to call on close, do it */ diff --git a/src/lib/Libnet/port_forwarding.c b/src/lib/Libnet/port_forwarding.c index f94092c3c19..8e206772888 100644 --- a/src/lib/Libnet/port_forwarding.c +++ b/src/lib/Libnet/port_forwarding.c @@ -19,8 +19,9 @@ #include #include "port_forwarding.h" - -#define ERR_MSG_LEN 1024 +#include "pbs_ifl.h" +#include "log.h" +#include "libutil.h" #define PF_LOGGER(logfunc, msg) if(logfunc != NULL) { logfunc(msg); } @@ -31,7 +32,7 @@ * should fork first since this function is an infinite loop and never returns */ /* __attribute__((noreturn)) - how do I do this portably? */ -int x11_reader_go =1; +int x11_reader_go = 1; extern int set_nodelay(int fd); @@ -65,7 +66,7 @@ port_forwarder( void (*logfunc) (char *)) { fd_set rfdset, wfdset, efdset; - int rc, maxsock = 0; + int rc; struct sockaddr_in from; pbs_socklen_t fromlen; int n, n2, sock; @@ -96,6 +97,8 @@ port_forwarder( } while (x11_reader_go) { + int maxsock; + FD_ZERO(&rfdset); FD_ZERO(&wfdset); FD_ZERO(&efdset); @@ -363,7 +366,12 @@ x11_connect_display( long alsounused) { int display_number, sock = 0; - char buf[1024], *cp; + /* + * buf will hold the display string consisting of host:screen so + * allow an extra 32 characters for the :screen portion + */ + char *buf; + char *cp; struct addrinfo hints, *ai, *aitop; char strport[NI_MAXSERV]; int gaierr; @@ -397,10 +405,11 @@ x11_connect_display( * Connect to an inet socket. The DISPLAY value is supposedly * hostname:d[.s], where hostname may also be numeric IP address. */ - strncpy(buf, display, sizeof(buf)); + pbs_asprintf(&buf, "%s", display); cp = strchr(buf, ':'); if (!cp) { fprintf(stderr, "Could not find ':' in DISPLAY: %.100s", display); + free(buf); return -1; } @@ -409,6 +418,7 @@ x11_connect_display( if (sscanf(cp + 1, "%d", &display_number) != 1) { fprintf(stderr, "Could not parse display number from DISPLAY: %.100s", display); + free(buf); return -1; } @@ -419,6 +429,7 @@ x11_connect_display( snprintf(strport, sizeof(strport), "%d", 6000 + display_number); if ((gaierr = getaddrinfo(buf, strport, &hints, &aitop)) != 0) { fprintf(stderr, "%100s: unknown host. (%s)", buf, gai_strerror(gaierr)); + free(buf); return -1; } @@ -446,9 +457,11 @@ x11_connect_display( if (!ai) { fprintf(stderr, "connect %.100s port %d: %.100s", buf, 6000 + display_number, strerror(errno)); + free(buf); return -1; } + free(buf); set_nodelay(sock); return sock; } diff --git a/src/lib/Libpython/pbs_python_external.c b/src/lib/Libpython/pbs_python_external.c index d320efce5f1..f5c867b7214 100644 --- a/src/lib/Libpython/pbs_python_external.c +++ b/src/lib/Libpython/pbs_python_external.c @@ -108,7 +108,6 @@ void pbs_python_ext_start_interpreter( struct python_interpreter_data *interp_data) { - static char func_id[] = "pbs_python_ext_start_interpreter"; #ifdef PYTHON /* -- BEGIN ONLY IF PYTHON IS CONFIGURED -- */ @@ -147,12 +146,12 @@ pbs_python_ext_start_interpreter( rc = stat(pbs_python_destlib, &sbuf); } if (rc != 0) { - log_err(-1, func_id, + log_err(-1, __func__, "--> PBS Python library directory not found <--"); return; } if (!S_ISDIR(sbuf.st_mode)) { - log_err(-1, func_id, + log_err(-1, __func__, "--> PBS Python library path is not a directory <--"); return; } @@ -166,7 +165,7 @@ pbs_python_ext_start_interpreter( return; } } else { /* we need to allocate memory */ - log_err(-1, func_id, + log_err(-1, __func__, "--> Passed NULL for interpreter data <--"); return; } @@ -191,14 +190,16 @@ pbs_python_ext_start_interpreter( /* Python script to be able to interrupt it */ if (Py_IsInitialized()) { + char *msgbuf; + interp_data->interp_started = 1; /* mark python as initialized */ /* print only the first five characters, TODO check for NULL? */ - snprintf(log_buffer, LOG_BUF_SIZE-1, - "--> Python Interpreter started, compiled with version:'%.*s' <--", - 5, Py_GetVersion()); - log_buffer[LOG_BUF_SIZE-1] = '\0'; + pbs_asprintf(&msgbuf, + "--> Python Interpreter started, compiled with version:'%s' <--", + Py_GetVersion()); log_event(evtype, PBS_EVENTCLASS_SERVER, - LOG_INFO, interp_data->daemon_name, log_buffer); + LOG_INFO, interp_data->daemon_name, msgbuf); + free(msgbuf); } else { log_err(-1, "Py_InitializeEx", "--> Failed to initialize Python interpreter <--"); @@ -214,7 +215,7 @@ pbs_python_ext_start_interpreter( "could not insert %s into sys.path shutting down", pbs_python_destlib); log_buffer[LOG_BUF_SIZE-1] = '\0'; - log_err(-1, func_id, log_buffer); + log_err(-1, __func__, log_buffer); goto ERROR_EXIT; } @@ -223,7 +224,7 @@ pbs_python_ext_start_interpreter( * the python modules. since the syspath is setup correctly */ if ((pbs_python_load_python_types(interp_data) == -1)) { - log_err(-1, func_id, "could not load python types into the interpreter"); + log_err(-1, __func__, "could not load python types into the interpreter"); goto ERROR_EXIT; } @@ -298,7 +299,6 @@ pbs_python_ext_shutdown_interpreter(struct python_interpreter_data *interp_data) void pbs_python_ext_quick_start_interpreter(void) { - static char func_id[] = "pbs_python_ext_quick_start_interpreter"; #ifdef PYTHON /* -- BEGIN ONLY IF PYTHON IS CONFIGURED -- */ @@ -330,13 +330,15 @@ pbs_python_ext_quick_start_interpreter(void) Py_InitializeEx(0); /* SKIP initialization of signals */ if (Py_IsInitialized()) { - snprintf(log_buffer, LOG_BUF_SIZE-1, - "--> Python Interpreter quick started, compiled with version:'%.*s' <--", - 5, Py_GetVersion()); - log_buffer[LOG_BUF_SIZE-1] = '\0'; + char *msgbuf; + + pbs_asprintf(&msgbuf, + "--> Python Interpreter quick started, compiled with version:'%s' <--", + Py_GetVersion()); log_event(PBSEVENT_SYSTEM|PBSEVENT_ADMIN | PBSEVENT_DEBUG, PBS_EVENTCLASS_SERVER, - LOG_INFO, func_id, log_buffer); + LOG_INFO, __func__, msgbuf); + free(msgbuf); } else { log_err(-1, "Py_InitializeEx", "--> Failed to quick initialize Python interpreter <--"); @@ -352,7 +354,7 @@ pbs_python_ext_quick_start_interpreter(void) "could not insert %s into sys.path shutting down", pbs_python_destlib); log_buffer[LOG_BUF_SIZE-1] = '\0'; - log_err(-1, func_id, log_buffer); + log_err(-1, __func__, log_buffer); goto ERROR_EXIT; } @@ -362,7 +364,7 @@ pbs_python_ext_quick_start_interpreter(void) log_buffer[LOG_BUF_SIZE-1] = '\0'; log_event(PBSEVENT_SYSTEM|PBSEVENT_ADMIN | PBSEVENT_DEBUG, PBS_EVENTCLASS_SERVER, - LOG_INFO, func_id, log_buffer); + LOG_INFO, __func__, log_buffer); return; @@ -417,12 +419,12 @@ pbs_python_ext_free_python_script( } return; } -#define COPY_STRING(dst,src) \ - do { \ - if (!((dst) = strdup(src))) { \ - log_err(errno, func_id, "could not copy string"); \ - goto ERROR_EXIT; \ - } \ +#define COPY_STRING(dst,src) \ + do { \ + if (!((dst) = strdup(src))) { \ + log_err(errno, __func__, "could not copy string"); \ + goto ERROR_EXIT; \ + } \ } while (0) int @@ -430,7 +432,6 @@ pbs_python_ext_alloc_python_script( const char *script_path, struct python_script **py_script /* returned value */ ) { - static char func_id[] = "pbs_python_ext_alloc_python_script"; #ifdef PYTHON /* --- BEGIN PYTHON BLOCK --- */ @@ -441,7 +442,7 @@ pbs_python_ext_alloc_python_script( *py_script = NULL; /* init, to be safe */ if (!(tmp_py_script = (struct python_script *) malloc(nbytes))) { - log_err(errno, func_id, "failed to malloc struct python_script"); + log_err(errno, __func__, "failed to malloc struct python_script"); goto ERROR_EXIT; } (void) memset(tmp_py_script, 0, nbytes); @@ -454,7 +455,7 @@ pbs_python_ext_alloc_python_script( snprintf(log_buffer, LOG_BUF_SIZE-1, "failed to stat <%s>", script_path); log_buffer[LOG_BUF_SIZE-1] = '\0'; - log_err(errno, func_id, log_buffer); + log_err(errno, __func__, log_buffer); goto ERROR_EXIT; } (void) memcpy(&(tmp_py_script->cur_sbuf), &sbuf, @@ -471,7 +472,7 @@ pbs_python_ext_alloc_python_script( return -1; #else - log_err(-1, func_id, "--> Python is disabled <--"); + log_err(-1, __func__, "--> Python is disabled <--"); return -1; #endif /* --- END PYTHON BLOCK --- */ } @@ -489,7 +490,6 @@ void * pbs_python_ext_namespace_init( struct python_interpreter_data *interp_data) { - static char func_id[] = "pbs_python_namespace_init"; #ifdef PYTHON /* --- BEGIN PYTHON BLOCK --- */ @@ -497,7 +497,7 @@ pbs_python_ext_namespace_init( namespace_dict = PyDict_New(); /* New Refrence MUST Decref */ if (!namespace_dict) { - pbs_python_write_error_to_log(func_id); + pbs_python_write_error_to_log(__func__); goto ERROR_EXIT; } /* @@ -507,7 +507,7 @@ pbs_python_ext_namespace_init( if ((PyDict_SetItemString(namespace_dict, "__builtins__", PyEval_GetBuiltins()) == -1) ) { - pbs_python_write_error_to_log(func_id); + pbs_python_write_error_to_log(__func__); goto ERROR_EXIT; } @@ -519,9 +519,9 @@ pbs_python_ext_namespace_init( pbs_v1_module_init()) == -1) ) { snprintf(log_buffer, LOG_BUF_SIZE-1, "%s|adding extension object", - func_id); + __func__); log_buffer[LOG_BUF_SIZE-1] = '\0'; - pbs_python_write_error_to_log(func_id); + pbs_python_write_error_to_log(__func__); goto ERROR_EXIT; } @@ -560,7 +560,6 @@ int pbs_python_check_and_compile_script(struct python_interpreter_data *interp_data, struct python_script *py_script) { - static char func_id[] = "pbs_python_check_and_compile_script"; #ifdef PYTHON /* -- BEGIN ONLY IF PYTHON IS CONFIGURED -- */ struct stat nbuf; /* new stat buf */ @@ -568,7 +567,7 @@ pbs_python_check_and_compile_script(struct python_interpreter_data *interp_data, int recompile = 1; if (!interp_data || !py_script) { - log_err(-1, func_id, "Either interp_data or py_script is NULL"); + log_err(-1, __func__, "Either interp_data or py_script is NULL"); return -1; } @@ -644,7 +643,6 @@ pbs_python_run_code_in_namespace(struct python_interpreter_data *interp_data, struct python_script *py_script, int *exit_code) { - static char func_id[] = "pbs_python_run_code_in_namespace"; #ifdef PYTHON /* -- BEGIN ONLY IF PYTHON IS CONFIGURED -- */ @@ -660,7 +658,7 @@ pbs_python_run_code_in_namespace(struct python_interpreter_data *interp_data, int rc=0; if (!interp_data || !py_script) { - log_err(-1, func_id, "Either interp_data or py_script is NULL"); + log_err(-1, __func__, "Either interp_data or py_script is NULL"); return -1; } @@ -708,7 +706,7 @@ pbs_python_run_code_in_namespace(struct python_interpreter_data *interp_data, /* make new namespace dictionary, NOTE new reference */ if (!(pdict = (PyObject *)pbs_python_ext_namespace_init(interp_data))) { - log_err(-1, func_id, "while calling pbs_python_ext_namespace_init"); + log_err(-1, __func__, "while calling pbs_python_ext_namespace_init"); return -1; } if ((pbs_python_setup_namespace_dict(pdict) == -1)) { @@ -792,7 +790,6 @@ static PyObject * _pbs_python_compile_file(const char *file_name, const char *compiled_code_file_name) { - static char func_id[] = "_pbs_python_compile_file"; FILE *fp = NULL; long len = 0; @@ -806,7 +803,7 @@ _pbs_python_compile_file(const char *file_name, snprintf(log_buffer, LOG_BUF_SIZE-1, "could not open file <%s>: %s\n", file_name, strerror(errno)); log_buffer[LOG_BUF_SIZE-1] = '\0'; - log_err(errno, func_id, log_buffer); + log_err(errno, __func__, log_buffer); goto ERROR_EXIT; } @@ -816,14 +813,14 @@ _pbs_python_compile_file(const char *file_name, snprintf(log_buffer, LOG_BUF_SIZE-1, "could not determine the file length: %s\n", strerror(errno)); log_buffer[LOG_BUF_SIZE-1] = '\0'; - log_err(errno, func_id, log_buffer); + log_err(errno, __func__, log_buffer); goto ERROR_EXIT; } if ((fseek(fp, 0L, SEEK_SET) == -1)) { snprintf(log_buffer, LOG_BUF_SIZE-1, "could not fseek to beginning: %s\n", strerror(errno)); log_buffer[LOG_BUF_SIZE-1] = '\0'; - log_err(errno, func_id, log_buffer); + log_err(errno, __func__, log_buffer); goto ERROR_EXIT; } file_sz = len; /* ok good we have a file size */ @@ -831,7 +828,7 @@ _pbs_python_compile_file(const char *file_name, snprintf(log_buffer, LOG_BUF_SIZE-1, "could not fseek to end: %s\n", strerror(errno)); log_buffer[LOG_BUF_SIZE-1] = '\0'; - log_err(errno, func_id, log_buffer); + log_err(errno, __func__, log_buffer); goto ERROR_EXIT; } /* allocate memory for file + \n\0 */ @@ -839,7 +836,7 @@ _pbs_python_compile_file(const char *file_name, if (!(file_buffer = (char *)PyMem_Malloc(sizeof(char)*file_sz))) { /* could not allocate memory */ - pbs_python_write_error_to_log(func_id); + pbs_python_write_error_to_log(__func__); goto ERROR_EXIT; } diff --git a/src/lib/Libpython/pbs_python_svr_internal.c b/src/lib/Libpython/pbs_python_svr_internal.c index 0225d67eeaa..ed59e1559cf 100644 --- a/src/lib/Libpython/pbs_python_svr_internal.c +++ b/src/lib/Libpython/pbs_python_svr_internal.c @@ -4559,7 +4559,7 @@ create_py_resvlist(pbs_list_head *resvlist) if ((plist_next == NULL) || (strcmp(plist->al_name, plist_next->al_name) != 0)) { - strncpy(rqs.rq_id, plist->al_name, sizeof(rqs.rq_id)); + snprintf(rqs.rq_id, sizeof(rqs.rq_id), "%s", plist->al_name); py_ra = Py_BuildValue("(s)", rqs.rq_id); /* NEW ref */ if (py_ra == NULL) { @@ -7643,6 +7643,7 @@ pbsv1mod_meth_is_attrib_val_settable(PyObject *self, PyObject *args, PyObject *k char dtype[STRBUF]; int dlen = 0; char *the_dtype = NULL; + char *msgbuf; memset(cls, '\0', STRBUF); memset(att, '\0', STRBUF); @@ -7678,20 +7679,21 @@ pbsv1mod_meth_is_attrib_val_settable(PyObject *self, PyObject *args, PyObject *k } } - snprintf(log_buffer, LOG_BUF_SIZE-1, + pbs_asprintf(&msgbuf, "value for class <%s> attribute <%s> must be 'None' or '%s%s%s'", - cls, att, vtype, the_dtype?",":"", - the_dtype?the_dtype:""); - log_buffer[LOG_BUF_SIZE-1] = '\0'; + cls, att, vtype, + the_dtype ? "," : "", + the_dtype ? the_dtype : ""); if (is_resource == 1) - PyErr_SetString(\ - pbs_python_types_table[PP_BAD_RESC_VTYPE_ERR_IDX].t_class, - log_buffer); + PyErr_SetString( + pbs_python_types_table[PP_BAD_RESC_VTYPE_ERR_IDX].t_class, + msgbuf); else - PyErr_SetString(\ - pbs_python_types_table[PP_BADATTR_VTYPE_ERR_IDX].t_class, - log_buffer); + PyErr_SetString( + pbs_python_types_table[PP_BADATTR_VTYPE_ERR_IDX].t_class, + msgbuf); + free(msgbuf); goto IAVS_ERROR_EXIT; } diff --git a/src/lib/Libtpp/tpp_client.c b/src/lib/Libtpp/tpp_client.c index f24fec87c4d..bc54d1943db 100644 --- a/src/lib/Libtpp/tpp_client.c +++ b/src/lib/Libtpp/tpp_client.c @@ -336,7 +336,7 @@ static int unshelve_pkt(stream_t *strm, int seq_no_acked); static void *add_part_packet(stream_t *strm, void *data, int sz); static int send_pkt_to_app(stream_t *strm, unsigned char type, void *data, int sz); static stream_t *find_stream_with_dest(tpp_addr_t *dest_addr, unsigned int dest_sd, unsigned int dest_magic); -static int tpp_send_inner(unsigned int sd, void *data, unsigned int len, unsigned int full_len, unsigned int cmprsd_len); +static int tpp_send_inner(int sd, void *data, int len, int full_len, int cmprsd_len); static int send_spl_packet(stream_t *strm, int type); static void flush_acks(stream_t *strm); static void tpp_clr_retry(tpp_packet_t *pkt, stream_t *strm); @@ -501,17 +501,17 @@ leaf_post_connect_handler(int tfd, void *data, void *c) { tpp_context_t *ctx = (tpp_context_t *) c; tpp_router_t *r; - int len; tpp_join_pkt_hdr_t hdr; tpp_chunk_t chunks[2]; - int i; if (!ctx) return 0; if (ctx->type == TPP_ROUTER_NODE) { - r = (tpp_router_t *) ctx->ptr; + int len; + int i; + r = (tpp_router_t *) ctx->ptr; r->state = TPP_ROUTER_STATE_CONNECTING; if (tpp_conf->auth_type == TPP_AUTH_EXTERNAL) { @@ -529,8 +529,11 @@ leaf_post_connect_handler(int tfd, void *data, void *c) } if ((adata = tpp_conf->get_ext_auth_data(tpp_conf->auth_type, &alen, ebuf, sizeof(ebuf))) == NULL) { - snprintf(tpp_get_logbuf(), TPP_LOGBUF_SZ, "Authentication failed: %s", ebuf); - tpp_log_func(LOG_CRIT, __func__, tpp_get_logbuf()); + char *msgbuf; + + pbs_asprintf(&msgbuf, "Authentication failed: %s", ebuf); + tpp_log_func(LOG_CRIT, __func__, msgbuf); + free(msgbuf); return -1; } @@ -860,7 +863,7 @@ tpp_open(char *dest_host, unsigned int port) tpp_unlock(&strmarray_lock); free(pkey); - TPP_DBPRT(("Stream for dest[%s] returned = %d", dest, strm->sd)); + TPP_DBPRT(("Stream for dest[%s] returned = %u", dest, strm->sd)); free(dest); return strm->sd; } @@ -1027,21 +1030,21 @@ get_active_router(int index) int tpp_send(int sd, void *data, int len) { - unsigned int to_send; + int to_send; void *p; unsigned int cmprsd_len = 0; - int send_len; tpp_packet_t *pkt = NULL; - void *outbuf; if (!get_strm(sd)) { TPP_DBPRT(("Bad sd %d", sd)); return -1; } - TPP_DBPRT(("Sending: sd=%u, len=%d", sd, len)); + TPP_DBPRT(("Sending: sd=%d, len=%d", sd, len)); + + if ((tpp_conf->compress == 1) && (len > TPP_SEND_SIZE)) { + void *outbuf; - if (tpp_conf->compress == 1 && len > TPP_SEND_SIZE) { outbuf = tpp_deflate(data, len, &cmprsd_len); if (outbuf == NULL) { tpp_log_func(LOG_CRIT, __func__, "tpp deflate failed"); @@ -1062,13 +1065,10 @@ tpp_send(int sd, void *data, int len) } if (to_send > 0) { - send_len = to_send; - to_send -= send_len; - if (tpp_send_inner(sd, p, send_len, len, cmprsd_len) != send_len) { + if (tpp_send_inner(sd, p, to_send, len, cmprsd_len) != to_send) { tpp_free_pkt(pkt); return -1; } - p = (char *) p + send_len; } tpp_free_pkt(pkt); return len; @@ -1101,7 +1101,7 @@ tpp_send(int sd, void *data, int len) * */ static int -tpp_send_inner(unsigned int sd, void *data, unsigned int len, unsigned int full_len, unsigned int cmprsd_len) +tpp_send_inner(int sd, void *data, int len, int full_len, int cmprsd_len) { stream_t *strm; tpp_data_pkt_hdr_t dhdr; @@ -1113,7 +1113,7 @@ tpp_send_inner(unsigned int sd, void *data, unsigned int len, unsigned int full_ return -1; } - TPP_DBPRT(("**** sd=%u, len=%d, compr_len=%d, totlen=%d, dest_sd=%u, seq=%u", sd, len, cmprsd_len, full_len, strm->dest_sd, strm->send_seq_no)); + TPP_DBPRT(("**** sd=%d, len=%d, compr_len=%d, totlen=%d, dest_sd=%u, seq=%u", sd, len, cmprsd_len, full_len, strm->dest_sd, strm->send_seq_no)); if (strm->strm_type == TPP_STRM_MCAST) { /* do other stuff */ @@ -1145,7 +1145,7 @@ tpp_send_inner(unsigned int sd, void *data, unsigned int len, unsigned int full_ app_thread_active_router = get_active_router(app_thread_active_router); if (app_thread_active_router == -1) { - TPP_DBPRT(("no active router, sending TPP_CMD_NET_CLOSE sd=%d", strm->sd)); + TPP_DBPRT(("no active router, sending TPP_CMD_NET_CLOSE sd=%u", strm->sd)); send_app_strm_close(strm, TPP_CMD_NET_CLOSE, 0); return -1; } @@ -1323,8 +1323,6 @@ static stream_t * alloc_stream(tpp_addr_t *src_addr, tpp_addr_t *dest_addr) { stream_t *strm; - void *p; - unsigned int newsize; unsigned int sd = max_strms, i; void *data; unsigned int freed_sd = UNINITIALIZED_INT; @@ -1389,6 +1387,9 @@ alloc_stream(tpp_addr_t *src_addr, tpp_addr_t *dest_addr) /* set to stream array */ if (max_strms == 0 || sd > max_strms - 1) { + unsigned int newsize; + void *p; + /* resize strmarray */ newsize = sd + 100; p = realloc(strmarray, sizeof(stream_slot_t) * newsize); @@ -1417,7 +1418,7 @@ alloc_stream(tpp_addr_t *src_addr, tpp_addr_t *dest_addr) } } - TPP_DBPRT(("*** Allocated new stream, sd=%d, src_magic=%d", strm->sd, strm->src_magic)); + TPP_DBPRT(("*** Allocated new stream, sd=%u, src_magic=%u", strm->sd, strm->src_magic)); tpp_unlock(&strmarray_lock); @@ -1666,7 +1667,7 @@ tpp_ready_fds(int *sds, int len) } sds[strms_found++] = sd; } else { - TPP_DBPRT(("Data recvd on closed stream %d discarded", sd)); + TPP_DBPRT(("Data recvd on closed stream %u discarded", sd)); tpp_free_pkt(pkt); /* respond back by sending the close packet once more * does not matter if it is a retry anyway @@ -1674,7 +1675,7 @@ tpp_ready_fds(int *sds, int len) send_spl_packet(strm, TPP_CLOSE_STRM); } } else { - TPP_DBPRT(("Data recvd on deleted stream %d discarded", sd)); + TPP_DBPRT(("Data recvd on deleted stream %u discarded", sd)); tpp_free_pkt(pkt); } } else if (cmd == TPP_CMD_PEER_CLOSE || cmd == TPP_CMD_NET_CLOSE) { @@ -1897,7 +1898,7 @@ tpp_close(int sd) tpp_lock(&strmarray_lock); - TPP_DBPRT(("Closing sd=%u", sd)); + TPP_DBPRT(("Closing sd=%d", sd)); /* free the recv_queue also */ while ((p = tpp_deque(&strm->recv_queue))) tpp_free_pkt(p); @@ -1945,7 +1946,7 @@ tpp_mcast_open(void) return -1; } - TPP_DBPRT(("tpp_mcast_open called with fd=%d", strm->sd)); + TPP_DBPRT(("tpp_mcast_open called with fd=%u", strm->sd)); strm->used_locally = 1; strm->strm_type = TPP_STRM_MCAST; @@ -2000,7 +2001,7 @@ tpp_mcast_add_strm(int mtfd, int tfd) free(mstrm->mcast_data); snprintf(tpp_get_logbuf(), TPP_LOGBUF_SZ, "Out of memory allocating strm array of %lu bytes", - (TPP_MCAST_SLOT_INC * sizeof(int))); + (unsigned long)(TPP_MCAST_SLOT_INC * sizeof(int))); tpp_log_func(LOG_CRIT, __func__, tpp_get_logbuf()); return -1; } @@ -2116,9 +2117,7 @@ static void tpp_mcast_notify_members(int mtfd, int cmd) { stream_t *mstrm; - stream_t *strm; int i; - int tfd; mstrm = get_strm_atomic(mtfd); if (!mstrm || !mstrm->mcast_data) { @@ -2127,6 +2126,9 @@ tpp_mcast_notify_members(int mtfd, int cmd) } for (i = 0; i < mstrm->mcast_data->num_fds; i++) { + int tfd; + stream_t *strm; + tfd = mstrm->mcast_data->strms[i]; strm = get_strm_atomic(tfd); if (!strm) @@ -2257,7 +2259,7 @@ tpp_mcast_send(int mtfd, void *data, unsigned int len, unsigned int full_len, un if (minfo_buf == NULL) goto err; - TPP_DBPRT(("*** mcast_send hdr orig=%d, cmprsd=%d", minfo_len, cmpr_len)); + TPP_DBPRT(("*** mcast_send hdr orig=%d, cmprsd=%u", minfo_len, cmpr_len)); chunks[1].data = minfo_buf; chunks[1].len = cmpr_len; @@ -2482,7 +2484,7 @@ strm_timeout_action(unsigned int sd) tpp_lock(&strmarray_lock); strm = strmarray[sd].strm; - TPP_DBPRT(("*** sd=%d timed out, closing", sd)); + TPP_DBPRT(("*** sd=%u timed out, closing", sd)); send_app_strm_close(strm, TPP_CMD_NET_CLOSE, 0); tpp_unlock(&strmarray_lock); @@ -2628,7 +2630,7 @@ find_stream_with_dest(tpp_addr_t *dest_addr, unsigned int dest_sd, unsigned int while (1) { strm = pkey->recptr; - TPP_DBPRT(("sd=%u, dest_sd=%u, u_state=%d, t-state=%d, dest_magic=%d", strm->sd, strm->dest_sd, strm->u_state, strm->t_state, strm->dest_magic)); + TPP_DBPRT(("sd=%u, dest_sd=%u, u_state=%d, t-state=%d, dest_magic=%u", strm->sd, strm->dest_sd, strm->u_state, strm->t_state, strm->dest_magic)); if (strm->dest_sd == dest_sd && strm->dest_magic == dest_magic) { free(pkey); return strm; @@ -2865,7 +2867,7 @@ shelve_mcast_pkt(tpp_mcast_pkt_hdr_t *mcast_hdr, int sd, int seq, tpp_packet_t * static int queue_ack(stream_t *strm, unsigned char type, unsigned int seq_no_recvd) { - ack_info_t *ack = NULL; + ack_info_t *ack; ack = malloc(sizeof(ack_info_t)); if (!ack) { @@ -3058,11 +3060,12 @@ static void check_pending_acks(time_t now) { tpp_que_elem_t *n = NULL; - ack_info_t *ack; stream_t *strm; int rc; while ((n = TPP_QUE_HEAD(&global_ack_queue))) { + ack_info_t *ack; + ack = TPP_QUE_DATA(n); if (ack && (ack->ack_time <= now)) { n = tpp_que_del_elem(&global_ack_queue, n); @@ -3150,14 +3153,15 @@ static void act_strm(time_t now, int force) { tpp_que_elem_t *n = NULL; - strm_action_info_t *c; tpp_lock(&strmarray_lock); while ((n = TPP_QUE_NEXT(&strm_action_queue, n))) { + strm_action_info_t *c; + c = TPP_QUE_DATA(n); if (c && ((c->strm_action_time <= now) || (force == 1))) { n = tpp_que_del_elem(&strm_action_queue, n); - TPP_DBPRT(("Calling action function for stream %d", c->sd)); + TPP_DBPRT(("Calling action function for stream %u", c->sd)); c->strm_action_func(c->sd); if (c->strm_action_func == free_stream) { /* free stream itself clears elements from the strm_action_queue @@ -3188,15 +3192,15 @@ static void check_retries(time_t now) { tpp_que_elem_t *n = NULL; - retry_info_t *rt; int sd; stream_t *strm; - tpp_packet_t *pkt; tpp_data_pkt_hdr_t *dhdr; int count_sent_to_transport = 0; - n = NULL; while ((n = TPP_QUE_NEXT(&global_retry_queue, n))) { + tpp_packet_t *pkt; + retry_info_t *rt; + pkt = TPP_QUE_DATA(n); rt = (retry_info_t *) pkt->extra_data; if (rt && (rt->retry_time <= now)) { @@ -3221,11 +3225,11 @@ check_retries(time_t now) if (strm && strm->t_state == TPP_TRNS_STATE_OPEN) { - TPP_DBPRT(("Sending retry packet for sd=%u seq=%u retry_time=%ld, pkt=%p", + TPP_DBPRT(("Sending retry packet for sd=%d seq=%u retry_time=%ld, pkt=%p", sd, ntohl(dhdr->seq_no), rt->retry_time, pkt)); if (send_retry_packet(pkt) != 0) { - sprintf(tpp_get_logbuf(), "Could not send retry, sending net_close for sd=%d", strm->sd); + sprintf(tpp_get_logbuf(), "Could not send retry, sending net_close for sd=%u", strm->sd); tpp_log_func(LOG_CRIT, __func__, tpp_get_logbuf()); send_app_strm_close(strm, TPP_CMD_NET_CLOSE, 0); } else { @@ -3468,7 +3472,7 @@ unshelve_pkt(stream_t *strm, int seq_no_acked) dhdr = (tpp_data_pkt_hdr_t *)(pkt->data + sizeof(int)); if (ntohl(dhdr->seq_no) == seq_no_acked) { rt->acked = 1; - TPP_DBPRT(("Releasing shelved packet sd=%u seq_no=%u type=%d", strm->sd, seq_no_acked, dhdr->type)); + TPP_DBPRT(("Releasing shelved packet sd=%u seq_no=%d type=%d", strm->sd, seq_no_acked, dhdr->type)); strm->num_unacked_pkts--; if (strm->num_unacked_pkts < 0) @@ -3532,7 +3536,7 @@ add_part_packet(stream_t *strm, void *data, int sz) q = (char *) data + sizeof(tpp_data_pkt_hdr_t); pkt = strm->part_recv_pkt; - TPP_DBPRT(("*** pkt=%p, sd=%u, sz=%d, totlen=%d, cmprsd_len=%d", (void *) pkt, strm->sd, sz, totlen, cmprsd_len)); + TPP_DBPRT(("*** pkt=%p, sd=%u, sz=%d, totlen=%d, cmprsd_len=%u", (void *) pkt, strm->sd, sz, totlen, cmprsd_len)); if (!pkt) { pkt = tpp_cr_pkt(NULL, totlen, 1); if (!pkt) @@ -3691,7 +3695,6 @@ static AVL_IX_REC * find_stream_tree_key(stream_t *strm) { AVL_IX_REC *pkey; - stream_t *t_strm; pkey = avlkey_create(AVL_streams, &strm->dest_addr); if (pkey == NULL) { @@ -3702,6 +3705,8 @@ find_stream_tree_key(stream_t *strm) if (avl_find_key(pkey, AVL_streams) == AVL_IX_OK) { do { + stream_t *t_strm; + t_strm = pkey->recptr; if (strm == t_strm) return pkey; @@ -3777,17 +3782,18 @@ free_stream_resources(stream_t *strm) static void free_stream(unsigned int sd) { - AVL_IX_REC *pkey; stream_t *strm; tpp_que_elem_t *n = NULL; strm_action_info_t *c; - TPP_DBPRT(("Freeing stream %d", sd)); + TPP_DBPRT(("Freeing stream %u", sd)); tpp_lock(&strmarray_lock); strm = strmarray[sd].strm; if (strm->strm_type != TPP_STRM_MCAST) { + AVL_IX_REC *pkey; + pkey = find_stream_tree_key(strm); if (pkey == NULL) { /* this should not happen ever */ @@ -3851,8 +3857,6 @@ leaf_pkt_presend_handler(int tfd, tpp_packet_t *pkt) { tpp_data_pkt_hdr_t *data = (tpp_data_pkt_hdr_t *)(pkt->data + sizeof(int)); unsigned char type = data->type; - unsigned int sd; - unsigned int ack_no; int len = *((int *)(pkt->data)); stream_t *strm; @@ -3861,6 +3865,8 @@ leaf_pkt_presend_handler(int tfd, tpp_packet_t *pkt) len = ntohl(len) - sizeof(tpp_data_pkt_hdr_t); if (type == TPP_CLOSE_STRM || (type == TPP_DATA && len > 0)) { + unsigned int sd; + unsigned int ack_no; sd = ntohl(data->src_sd); ack_no = ntohl(data->ack_seq); @@ -3882,7 +3888,7 @@ leaf_pkt_presend_handler(int tfd, tpp_packet_t *pkt) /* if packet cannot be sent now then shelve them */ if (strm->num_unacked_pkts > rpp_highwater) { snprintf(tpp_get_logbuf(), TPP_LOGBUF_SZ, - "Stream %d reached highwater, %d, throttling, seq=%d", sd, + "Stream %u reached highwater, %d, throttling, seq=%d", sd, strm->num_unacked_pkts, ntohl(data->seq_no)); tpp_log_func(LOG_CRIT, NULL, tpp_get_logbuf()); if (shelve_pkt(pkt, NULL, now + TPP_THROTTLE_RETRY) != 0) { @@ -4213,7 +4219,7 @@ leaf_pkt_handler(int tfd, void *data, int len, void *ctx) strm = get_strm_atomic(src_sd); if (strm) { char *msg = ((char *) data) + sizeof(tpp_ctl_pkt_hdr_t); - snprintf(tpp_get_logbuf(), TPP_LOGBUF_SZ, "sd %d, Received noroute to dest %s, msg=\"%s\"", src_sd, + snprintf(tpp_get_logbuf(), TPP_LOGBUF_SZ, "sd %u, Received noroute to dest %s, msg=\"%s\"", src_sd, tpp_netaddr(&hdr->src_addr), msg); #ifdef NAS /* localmod 149 */ tpp_log_func(LOG_DEBUG, NULL, tpp_get_logbuf()); @@ -4221,7 +4227,7 @@ leaf_pkt_handler(int tfd, void *data, int len, void *ctx) tpp_log_func(LOG_INFO, NULL, tpp_get_logbuf()); #endif /* localmod 149 */ - TPP_DBPRT(("received noroute, sending TPP_CMD_NET_CLOSE to %d", strm->sd)); + TPP_DBPRT(("received noroute, sending TPP_CMD_NET_CLOSE to %u", strm->sd)); send_app_strm_close(strm, TPP_CMD_NET_CLOSE, 0); } return 0; @@ -4299,7 +4305,7 @@ leaf_pkt_handler(int tfd, void *data, int len, void *ctx) tpp_unlock(&strmarray_lock); while ((strm = (stream_t *) tpp_deque(&send_close_queue))) { - TPP_DBPRT(("received TPP_CTL_LEAVE, sending TPP_CMD_NET_CLOSE sd=%d", strm->sd)); + TPP_DBPRT(("received TPP_CTL_LEAVE, sending TPP_CMD_NET_CLOSE sd=%u", strm->sd)); send_app_strm_close(strm, TPP_CMD_NET_CLOSE, hdr->ecode); } @@ -4318,7 +4324,6 @@ leaf_pkt_handler(int tfd, void *data, int len, void *ctx) unsigned int src_sd; unsigned int dest_sd; unsigned int src_magic; - int seq_no_diff; unsigned int sz = len - sizeof(tpp_data_pkt_hdr_t); src_sd = ntohl(p->src_sd); @@ -4354,7 +4359,7 @@ leaf_pkt_handler(int tfd, void *data, int len, void *ctx) } dest_sd = strm->sd; } else { - TPP_DBPRT(("Stream found from index in packet = %d", dest_sd)); + TPP_DBPRT(("Stream found from index in packet = %u", dest_sd)); } /* In any case, check for the stream's validity */ @@ -4380,7 +4385,7 @@ leaf_pkt_handler(int tfd, void *data, int len, void *ctx) strm->dest_magic = src_magic; /* used for matching next time onwards */ seq_no_expected = strm->seq_no_expected; - TPP_DBPRT(("sequence_no expected = %d", seq_no_expected)); + TPP_DBPRT(("sequence_no expected = %u", seq_no_expected)); sd = strm->sd; @@ -4454,6 +4459,7 @@ leaf_pkt_handler(int tfd, void *data, int len, void *ctx) } else { tpp_que_elem_t *n; tpp_packet_t *full_pkt; + int seq_no_diff; /* * Check the sequence number in the packet, if duplicate drop it, @@ -4502,7 +4508,7 @@ leaf_pkt_handler(int tfd, void *data, int len, void *ctx) unsigned int seq_no = (unsigned int) ntohl(shdr->seq_no); if (seq_no == seq_no_recvd) { /* duplicate packet */ - snprintf(tpp_get_logbuf(), TPP_LOGBUF_SZ, "Recvd duplicate packet seq_no=%d, dup=%d", seq_no_recvd, shdr->dup); + snprintf(tpp_get_logbuf(), TPP_LOGBUF_SZ, "Recvd duplicate packet seq_no=%u, dup=%d", seq_no_recvd, shdr->dup); tpp_log_func(LOG_CRIT, NULL, tpp_get_logbuf()); tpp_free_pkt(full_pkt); @@ -4512,7 +4518,7 @@ leaf_pkt_handler(int tfd, void *data, int len, void *ctx) /* insert it here and return */ n = tpp_que_ins_elem(&strm->oo_queue, n, full_pkt, 1); - snprintf(tpp_get_logbuf(), TPP_LOGBUF_SZ, "Inserted OO packet with seq_no = %d for sd=%u", seq_no_recvd, + snprintf(tpp_get_logbuf(), TPP_LOGBUF_SZ, "Inserted OO packet with seq_no = %u for sd=%u", seq_no_recvd, strm->sd); tpp_log_func(LOG_INFO, NULL, tpp_get_logbuf()); return 0; @@ -4521,7 +4527,7 @@ leaf_pkt_handler(int tfd, void *data, int len, void *ctx) } /* if it came here then packet was not inserted, so insert at end */ if (tpp_enque(&strm->oo_queue, full_pkt) == NULL) { - snprintf(tpp_get_logbuf(), TPP_LOGBUF_SZ, "Failed to enque OO packet for sd = %d, Out of memory", strm->sd); + snprintf(tpp_get_logbuf(), TPP_LOGBUF_SZ, "Failed to enque OO packet for sd = %u, Out of memory", strm->sd); tpp_log_func(LOG_CRIT, NULL, tpp_get_logbuf()); return -1; } @@ -4566,7 +4572,6 @@ leaf_pkt_handler(int tfd, void *data, int len, void *ctx) int leaf_close_handler(int tfd, int error, void *c) { - unsigned int i; int rc; tpp_context_t *ctx = (tpp_context_t *) c; tpp_router_t *r; @@ -4603,6 +4608,8 @@ leaf_close_handler(int tfd, int error, void *c) active_router = get_active_router(active_router); if (active_router == -1) { + unsigned int i; + /* * No routers available, let app know of this */ @@ -4612,7 +4619,7 @@ leaf_close_handler(int tfd, int error, void *c) for (i = 0; i < max_strms; i++) { if (strmarray[i].slot_state == TPP_SLOT_BUSY) { strmarray[i].strm->t_state = TPP_TRNS_STATE_NET_CLOSED; - TPP_DBPRT(("net down, sending TPP_CMD_NET_CLOSE sd=%d", strmarray[i].strm->sd)); + TPP_DBPRT(("net down, sending TPP_CMD_NET_CLOSE sd=%u", strmarray[i].strm->sd)); send_app_strm_close(strmarray[i].strm, TPP_CMD_NET_CLOSE, 0); } } @@ -4622,7 +4629,7 @@ leaf_close_handler(int tfd, int error, void *c) for (i = 0; i < max_strms; i++) { if (strmarray[i].slot_state == TPP_SLOT_BUSY) { strmarray[i].strm->t_state = TPP_TRNS_STATE_NET_CLOSED; - TPP_DBPRT(("net down, sending TPP_CMD_NET_CLOSE sd=%d", strmarray[i].strm->sd)); + TPP_DBPRT(("net down, sending TPP_CMD_NET_CLOSE sd=%u", strmarray[i].strm->sd)); send_app_strm_close(strmarray[i].strm, TPP_CMD_NET_CLOSE, 0); } } diff --git a/src/lib/Libtpp/tpp_router.c b/src/lib/Libtpp/tpp_router.c index 1f90fb00cab..81247501cbe 100644 --- a/src/lib/Libtpp/tpp_router.c +++ b/src/lib/Libtpp/tpp_router.c @@ -117,7 +117,7 @@ static tpp_router_t *this_router = NULL; static tpp_router_t * alloc_router(char *name, tpp_addr_t *address) { - tpp_router_t *r = NULL; + tpp_router_t *r; tpp_addr_t *addrs = NULL; int count = 0; @@ -490,8 +490,7 @@ static int router_post_connect_handler(int tfd, void *data, void *c) { tpp_context_t *ctx = (tpp_context_t *) c; - tpp_router_t *r; - int rc; + int rc = 0; tpp_join_pkt_hdr_t hdr; tpp_chunk_t chunks[2]; @@ -499,7 +498,7 @@ router_post_connect_handler(int tfd, void *data, void *c) return 0; if (ctx->type == TPP_ROUTER_NODE) { - r = (tpp_router_t *) ctx->ptr; + tpp_router_t *r = (tpp_router_t *) ctx->ptr; if (tpp_conf->auth_type == TPP_AUTH_EXTERNAL) { char ebuf[TPP_LOGBUF_SZ]; @@ -517,8 +516,11 @@ router_post_connect_handler(int tfd, void *data, void *c) } if ((adata = tpp_conf->get_ext_auth_data(tpp_conf->auth_type, &alen, ebuf, sizeof(ebuf))) == NULL) { - snprintf(tpp_get_logbuf(), TPP_LOGBUF_SZ, "Authentication failed: %s", ebuf); - tpp_log_func(LOG_CRIT, __func__, tpp_get_logbuf()); + char *msgbuf; + + pbs_asprintf(&msgbuf, "Authentication failed: %s", ebuf); + tpp_log_func(LOG_CRIT, __func__, msgbuf); + free(msgbuf); return -1; } @@ -563,7 +565,7 @@ router_post_connect_handler(int tfd, void *data, void *c) return 0; } } - return 0; + return rc; } /** @@ -725,13 +727,14 @@ router_close_handler_inner(int tfd, int error, void *c, int hop) } else if (ctx->type == TPP_ROUTER_NODE) { tpp_router_t *r = (tpp_router_t *) ctx->ptr; - AVL_IX_REC *pkey; int rc; tpp_leaf_t *l; tpp_que_t deleted_leaves; tpp_que_elem_t *n = NULL; if (r->state == TPP_ROUTER_STATE_CONNECTED) { + AVL_IX_REC *pkey; + /* do any logging or leaf processing only if it was connected earlier */ snprintf(tpp_get_logbuf(), TPP_LOGBUF_SZ, @@ -782,6 +785,8 @@ router_close_handler_inner(int tfd, int error, void *c, int hop) /* now remove each of the leaf's addresses from avl_clusters */ while ((n = TPP_QUE_NEXT(&deleted_leaves, n))) { l = (tpp_leaf_t *) TPP_QUE_DATA(n); + if (l == NULL) + continue; if (l->leaf_type == TPP_LEAF_NODE_LISTEN) { tree_add_del(AVL_my_leaves_notify, &l->leaf_addrs[0], NULL, TREE_OP_DEL); @@ -976,7 +981,6 @@ router_timer_handler(time_t now) { tpp_ctl_pkt_hdr_t hdr; tpp_chunk_t chunks[1]; - int len; int send_update = 0; int ret = -1; @@ -992,6 +996,8 @@ router_timer_handler(time_t now) tpp_unlock(&router_lock); if (send_update == 1) { + int len; + hdr.type = TPP_CTL_MSG; hdr.code = TPP_MSG_UPDATE; @@ -1093,9 +1099,14 @@ router_pkt_handler(int tfd, void *data, int len, void *c) rc = tpp_conf->validate_ext_auth_data(TPP_AUTH_EXTERNAL, adata, alen, ebuf, sizeof(ebuf)); if (rc != 0) { - snprintf(tpp_get_logbuf(), TPP_LOGBUF_SZ, "tfd=%d connection from %s failed authentication. %s", tfd, tpp_netaddr(&connected_host), ebuf); - tpp_log_func(LOG_CRIT, NULL, tpp_get_logbuf()); - tpp_send_ctl_msg(tfd, TPP_MSG_AUTHERR, &connected_host, &this_router->router_addr, -1, rc, tpp_get_logbuf()); + char *msgbuf; + + pbs_asprintf(&msgbuf, + "tfd=%d connection from %s failed authentication. %s", + tfd, tpp_netaddr(&connected_host), ebuf); + tpp_log_func(LOG_CRIT, NULL, msgbuf); + tpp_send_ctl_msg(tfd, TPP_MSG_AUTHERR, &connected_host, &this_router->router_addr, -1, rc, msgbuf); + free(msgbuf); free(adata); return 0; /* let connection be alive, so we can send error */ } @@ -1154,7 +1165,7 @@ router_pkt_handler(int tfd, void *data, int len, void *c) /* check if type was router or leaf */ if (node_type == TPP_ROUTER_NODE) { - tpp_router_t *r = NULL; + tpp_router_t *r; TPP_DBPRT(("Recvd TPP_CTL_JOIN from pbs_comm node %s", tpp_netaddr(&connected_host))); @@ -1477,10 +1488,8 @@ router_pkt_handler(int tfd, void *data, int len, void *c) break; /* TPP_CTL_LEAVE */ case TPP_MCAST_DATA: { - tpp_leaf_t *l; int i, k; - unsigned int src_sd; - tpp_addr_t *src_host, *dest_host; + tpp_addr_t *src_host; int *rlist = NULL; int rsize = 0; int csize = 0; @@ -1514,7 +1523,7 @@ router_pkt_handler(int tfd, void *data, int len, void *c) orig_hop = mhdr->hop; snprintf(tpp_get_logbuf(), TPP_LOGBUF_SZ, - "tfd=%d, MCAST packet from %s, %d member streams, cmprsd_len=%d, info_len=%d, len=%d", + "tfd=%d, MCAST packet from %s, %u member streams, cmprsd_len=%d, info_len=%d, len=%d", tfd, tpp_netaddr(src_host), num_streams, cmprsd_len, info_len, payload_len); tpp_log_func(LOG_INFO, NULL, tpp_get_logbuf()); @@ -1548,13 +1557,16 @@ router_pkt_handler(int tfd, void *data, int len, void *c) * first to other routers and then to local nodes */ for (k = num_streams - 1; k >= 0; k--) { + tpp_addr_t *dest_host; + unsigned int src_sd; + tpp_leaf_t *l; minfo = (tpp_mcast_pkt_info_t *)(((char *) minfo_base) + k * sizeof(tpp_mcast_pkt_info_t)); dest_host = &minfo->dest_addr; src_sd = ntohl(minfo->src_sd); - TPP_DBPRT(("MCAST data on fd=%d", src_sd)); + TPP_DBPRT(("MCAST data on fd=%u", src_sd)); tpp_lock(&router_lock); l = find_tree(AVL_cluster_leaves, dest_host); @@ -1610,7 +1622,7 @@ router_pkt_handler(int tfd, void *data, int len, void *c) if (cmprsd_len > 0) free(minfo_base); snprintf(tpp_get_logbuf(), TPP_LOGBUF_SZ, "Out of memory allocating pbs_comm list of %lu bytes", - sizeof(int) * rsize); + (unsigned long)(sizeof(int) * rsize)); tpp_log_func(LOG_CRIT, __func__, tpp_get_logbuf()); return -1; } @@ -1641,7 +1653,7 @@ router_pkt_handler(int tfd, void *data, int len, void *c) if (cmprsd_len > 0) free(minfo_base); snprintf(tpp_get_logbuf(), TPP_LOGBUF_SZ, "Out of memory resizing pbs_comm list to %lu bytes", - sizeof(int) * rsize); + (unsigned long)(sizeof(int) * rsize)); tpp_log_func(LOG_CRIT, __func__, tpp_get_logbuf()); return -1; } @@ -1904,8 +1916,6 @@ del_router_from_leaf(tpp_leaf_t *l, int tfd) static int add_route_to_leaf(tpp_leaf_t *l, tpp_router_t *r, int index) { - int sz, i; - /* * Associate the router with the leaf * @@ -1917,6 +1927,9 @@ add_route_to_leaf(tpp_leaf_t *l, tpp_router_t *r, int index) return -1; /* error - index must be set before calling add route */ if (index >= l->tot_routers) { + int sz; + int i; + sz = index + 3; l->r = realloc(l->r, sz * sizeof(tpp_router_t *)); for (i = l->tot_routers; i < sz; i++) @@ -1928,13 +1941,16 @@ add_route_to_leaf(tpp_leaf_t *l, tpp_router_t *r, int index) l->num_routers++; #ifdef DEBUG - fprintf(stderr, "Leaf %s:%d routers [", tpp_netaddr(&l->leaf_addrs[0]), l->conn_fd); - for (i = 0; i < l->tot_routers; i++) { - if (l->r[i] && l->r[i]->router_name) - fprintf(stderr, "%s:%d,", l->r[i]->router_name, l->r[i]->conn_fd); - } - fprintf(stderr, "],router_count=%d\n", l->num_routers); + { + int i; + fprintf(stderr, "Leaf %s:%d routers [", tpp_netaddr(&l->leaf_addrs[0]), l->conn_fd); + for (i = 0; i < l->tot_routers; i++) { + if (l->r[i] && l->r[i]->router_name) + fprintf(stderr, "%s:%d,", l->r[i]->router_name, l->r[i]->conn_fd); + } + fprintf(stderr, "],router_count=%d\n", l->num_routers); + } #endif return index; diff --git a/src/lib/Libtpp/tpp_transport.c b/src/lib/Libtpp/tpp_transport.c index 4bf4f404594..8ea7dd500de 100644 --- a/src/lib/Libtpp/tpp_transport.c +++ b/src/lib/Libtpp/tpp_transport.c @@ -235,7 +235,7 @@ static phy_conn_t *get_transport_atomic(int tfd, int *slot_state); static void enque_lazy_connect(thrd_data_t *td, int tfd, int delay) { - conn_event_t *conn_ev, *p; + conn_event_t *conn_ev; tpp_que_elem_t *n; void *ret; @@ -249,6 +249,8 @@ enque_lazy_connect(thrd_data_t *td, int tfd, int delay) n = NULL; while ((n = TPP_QUE_NEXT(&td->lazy_conn_que, n))) { + conn_event_t *p; + p = TPP_QUE_DATA(n); /* sorted list, insert before node which has higher time */ @@ -292,7 +294,9 @@ trigger_lazy_connects(thrd_data_t *td, time_t now) while ((n = TPP_QUE_NEXT(&td->lazy_conn_que, n))) { q = TPP_QUE_DATA(n); - if (q && (now >= q->conn_time)) { + if (q == NULL) + continue; + if (now >= q->conn_time) { (void) get_transport_atomic(q->tfd, &slot_state); if (slot_state == TPP_SLOT_BUSY) handle_cmd(td, q->tfd, TPP_CMD_ASSIGN, NULL); @@ -427,15 +431,18 @@ tpp_cr_server_socket(int port) return -1; } if (tpp_sock_bind(sd, (struct sockaddr *) &serveraddr, sizeof(serveraddr)) == -1) { + char *msgbuf; #ifdef HAVE_STRERROR_R char buf[TPP_LOGBUF_SZ + 1]; + if (strerror_r(errno, buf, sizeof(buf)) == 0) - snprintf(tpp_get_logbuf(), TPP_LOGBUF_SZ, "%s while binding to port %d", buf, port); + pbs_asprintf(&msgbuf, "%s while binding to port %d", buf, port); else #endif - snprintf(tpp_get_logbuf(), TPP_LOGBUF_SZ, "Error %d while binding to port %d", errno, port); - tpp_log_func(LOG_CRIT, NULL, tpp_get_logbuf()); - fprintf(stderr, "%s", tpp_get_logbuf()); + pbs_asprintf(&msgbuf, "Error %d while binding to port %d", errno, port); + tpp_log_func(LOG_CRIT, NULL, msgbuf); + fprintf(stderr, "%s", msgbuf); + free(msgbuf); return -1; } if (tpp_sock_listen(sd, 1000) == -1) { @@ -698,8 +705,6 @@ static phy_conn_t* alloc_conn(int tfd) { phy_conn_t *conn; - void *p; - int newsize; conn = calloc(1, sizeof(phy_conn_t)); if (!conn) { @@ -714,6 +719,9 @@ alloc_conn(int tfd) /* set to stream array */ tpp_lock(&cons_array_lock); if (tfd >= conns_array_size - 1) { + int newsize; + void *p; + /* resize conns */ newsize = tfd + 100; p = realloc(conns_array, sizeof(conns_array_type_t) * newsize); @@ -1209,7 +1217,6 @@ assign_to_worker(int tfd, int delay, thrd_data_t *td) { int slot_state; phy_conn_t *conn; - int iters=0; conn = get_transport_atomic(tfd, &slot_state); if (conn == NULL || slot_state != TPP_SLOT_BUSY) @@ -1221,6 +1228,8 @@ assign_to_worker(int tfd, int delay, thrd_data_t *td) } if (td == NULL) { + int iters = 0; + tpp_lock(&thrd_array_lock); /* find a thread index to assign to, since none provided */ do { @@ -1313,18 +1322,23 @@ add_transport_conn(phy_conn_t *conn) if (tpp_sock_attempt_connection(conn->sock_fd, conn->conn_params->hostname, conn->conn_params->port) == -1) { if (errno != EINPROGRESS && errno != EWOULDBLOCK && errno != EAGAIN) { + char *msgbuf; #ifdef HAVE_STRERROR_R char buf[TPP_LOGBUF_SZ + 1]; + if (strerror_r(errno, buf, sizeof(buf)) == 0) - snprintf(tpp_get_logbuf(), TPP_LOGBUF_SZ, - "%s while connecting to %s:%d", buf, conn->conn_params->hostname, + pbs_asprintf(&msgbuf, + "%s while connecting to %s:%d", buf, + conn->conn_params->hostname, conn->conn_params->port); else #endif - snprintf(tpp_get_logbuf(), TPP_LOGBUF_SZ, - "Error %d while connecting to %s:%d", errno, conn->conn_params->hostname, + pbs_asprintf(&msgbuf, + "Error %d while connecting to %s:%d", errno, + conn->conn_params->hostname, conn->conn_params->port); - tpp_log_func(LOG_ERR, NULL, tpp_get_logbuf()); + tpp_log_func(LOG_ERR, NULL, msgbuf); + free(msgbuf); return -1; } } else { @@ -1907,12 +1921,13 @@ handle_incoming_data(phy_conn_t *conn) { int rc; int torecv = 0; - int space_left = 0; - int offset = 0; - int closed = 0; - int amt = 0; while (1) { + int space_left; + int offset; + int closed; + int amt; + offset = conn->scratch.pos - conn->scratch.data; space_left = conn->scratch.len - offset; /* remaining space */ if (space_left == 0) { @@ -1999,9 +2014,6 @@ handle_incoming_data(phy_conn_t *conn) static int add_pkts(phy_conn_t *conn) { - int pkt_len = 0; - int data_len = 0; - char *data; char *pkt_start; int avl_len; int rc = 0; @@ -2014,6 +2026,9 @@ add_pkts(phy_conn_t *conn) avl_len = recv_len; while (avl_len >= (sizeof(int) + sizeof(char))) { + int pkt_len; + int data_len; + char *data; /* We have enough data now to validate the header */ if (tpp_validate_hdr(tfd, pkt_start) != 0) { @@ -2070,7 +2085,6 @@ static void send_data(phy_conn_t *conn) { tpp_packet_t *p = NULL; - int tosend = 0; int rc; int can_send_more; tpp_que_elem_t *n; @@ -2096,6 +2110,8 @@ send_data(phy_conn_t *conn) can_send_more = 1; while (p && can_send_more) { + int tosend; + tosend = p->len - (p->pos - p->data); if (p->pos == p->data) { if (the_pkt_presend_handler) { diff --git a/src/lib/Libtpp/tpp_util.c b/src/lib/Libtpp/tpp_util.c index a94e99745ea..565697ed239 100644 --- a/src/lib/Libtpp/tpp_util.c +++ b/src/lib/Libtpp/tpp_util.c @@ -1775,12 +1775,14 @@ tpp_netaddr(tpp_addr_t *ap) * to print hostname along with ip */ if (tpp_log_event_mask >= (PBSEVENT_DEBUG4 - 1)) { - char tmp_buf[1024]; char host[256]; if (tpp_sock_resolve_ip(ap, host, sizeof(host)) == 0) { - snprintf(tmp_buf, sizeof(tmp_buf), "(%s)%s", host, ptr->tppstaticbuf); + char *tmp_buf; + + pbs_asprintf(&tmp_buf, "(%s)%s", host, ptr->tppstaticbuf); strcpy(ptr->tppstaticbuf, tmp_buf); + free(tmp_buf); } } diff --git a/src/lib/Libutil/daemon_protect.c b/src/lib/Libutil/daemon_protect.c index 5653a099478..25b745882a8 100644 --- a/src/lib/Libutil/daemon_protect.c +++ b/src/lib/Libutil/daemon_protect.c @@ -7,10 +7,7 @@ #include #include #include "server_limits.h" - -#ifndef MAXPATHLEN -#define MAXPATHLEN 1024 -#endif +#include "pbs_ifl.h" /** * @brief diff --git a/src/lib/Libutil/hook.c b/src/lib/Libutil/hook.c index cb6d9886d31..b29d07ff017 100644 --- a/src/lib/Libutil/hook.c +++ b/src/lib/Libutil/hook.c @@ -2668,9 +2668,11 @@ hook_save(hook *phook) return (-1); } if (rename(hookfile_new, hookfile) < 0) { - sprintf(log_buffer, "rename(%s, %s) failed!", - hookfile_new, hookfile); - log_err(errno, __func__, log_buffer); + char *msgbuf; + + pbs_asprintf(&msgbuf, "rename(%s, %s) failed!", hookfile_new, hookfile); + log_err(errno, __func__, msgbuf); + free(msgbuf); (void)unlink(hookfile_new); return (-1); } diff --git a/src/lib/Libutil/misc_utils.c b/src/lib/Libutil/misc_utils.c index 026a631c3e8..109ca2ccc1e 100644 --- a/src/lib/Libutil/misc_utils.c +++ b/src/lib/Libutil/misc_utils.c @@ -65,6 +65,7 @@ #include #include #include +#include #include #include #include @@ -403,6 +404,70 @@ pbs_fgets_extend(char **pbuf, int *pbuf_size, FILE *fp) return buf; } +/** + * @brief + * Internal asprintf() implementation for use on all platforms + * + * @param[in, out] dest - character pointer that will point to allocated + * space ** must be freed by caller ** + * @param[in] fmt - format for printed string + * @param[in] ... - arguments to format string + * + * @return int + * @retval -1 - Error + * @retval >=0 - Length of new string, not including terminator + */ +int +pbs_asprintf(char **dest, const char *fmt, ...) +{ + va_list args; + int len, rc = -1; + char *buf = NULL; + + if (!dest) + return -1; + *dest = NULL; + if (!fmt) + return -1; + va_start(args, fmt); +#ifdef WIN32 + len = _vscprintf(fmt, args); +#else + { + va_list dupargs; + char c; + + va_copy(dupargs, args); + len = vsnprintf(&c, 0, fmt, dupargs); + va_end(dupargs); + } +#endif + if (len < 0) + goto pbs_asprintf_exit; + buf = malloc(len + 1); + if (!buf) + goto pbs_asprintf_exit; + rc = vsnprintf(buf, len + 1, fmt, args); + if (rc != len) { + rc = -1; + goto pbs_asprintf_exit; + } + *dest = buf; +pbs_asprintf_exit: + va_end(args); + if (rc < 0) { + char *tmp; + + tmp = realloc(buf, 1); + if (tmp) + buf = tmp; + if (buf) { + *buf = '\0'; + *dest = buf; + } + } + return rc; +} /** @@ -1171,7 +1236,7 @@ convert_duration_to_str(time_t duration, char* buf, int bufsize) snprintf(buf, bufsize, "%02ld:%02ld:%02ld", hour, min, sec); } -/* +/** * @brief * Determines if 'str' ends with three consecutive double quotes, * before a newline (if it exists). @@ -1228,7 +1293,7 @@ ends_with_triple_quotes(char *str, int strip_quotes) return (0); } -/* +/** * @brief * Determines if 'str' begins with three consecutive double quotes. * diff --git a/src/lib/Libutil/pbs_ical.c b/src/lib/Libutil/pbs_ical.c index f03112a38c5..45000d91ef7 100644 --- a/src/lib/Libutil/pbs_ical.c +++ b/src/lib/Libutil/pbs_ical.c @@ -112,9 +112,9 @@ get_num_occurrences(char *rrule, time_t dtstart, char *tz) icalerror_set_error_state(ICAL_PARSE_ERROR, ICAL_ERROR_NONFATAL); #ifdef LIBICAL_API2 - icalerror_set_errors_are_fatal(0); + icalerror_set_errors_are_fatal(0); #else - icalerror_errors_are_fatal = 0; + icalerror_errors_are_fatal = 0; #endif localzone = icaltimezone_get_builtin_timezone(tz); @@ -196,9 +196,9 @@ get_occurrence(char *rrule, time_t dtstart, char *tz, int idx) icalerror_set_error_state(ICAL_PARSE_ERROR, ICAL_ERROR_NONFATAL); #ifdef LIBICAL_API2 - icalerror_set_errors_are_fatal(0); + icalerror_set_errors_are_fatal(0); #else - icalerror_errors_are_fatal = 0; + icalerror_errors_are_fatal = 0; #endif localzone = icaltimezone_get_builtin_timezone(tz); @@ -285,9 +285,9 @@ check_rrule(char *rrule, time_t dtstart, time_t dtend, char *tz, int *err_code) icalerror_set_error_state(ICAL_PARSE_ERROR, ICAL_ERROR_NONFATAL); #ifdef LIBICAL_API2 - icalerror_set_errors_are_fatal(0); + icalerror_set_errors_are_fatal(0); #else - icalerror_errors_are_fatal = 0; + icalerror_errors_are_fatal = 0; #endif if (tz == NULL || rrule == NULL) diff --git a/src/mom_rcp/rcp.c b/src/mom_rcp/rcp.c index 99482fea29c..d56bba335b8 100644 --- a/src/mom_rcp/rcp.c +++ b/src/mom_rcp/rcp.c @@ -68,15 +68,12 @@ * */ -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1983, 1990, 1992, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static const char sccsid[] = "@(#)rcp.c 8.2 (Berkeley) 4/2/94"; -#endif /* not lint */ +/* + * Copyright (c) 1983, 1990, 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * rcp.c 8.2 (Berkeley) 4/2/94"; + */ #include /* the master config generated by configure */ @@ -105,6 +102,7 @@ static const char sccsid[] = "@(#)rcp.c 8.2 (Berkeley) 4/2/94"; #include "pbs_version.h" #include "pbs_stat.h" #include "libutil.h" +#include "pbs_ifl.h" #ifdef USELOG #include @@ -145,11 +143,6 @@ utimes(const char *path, const struct timeval *times) } #endif - -#ifndef MAXPATHLEN -#define MAXPATHLEN 1024 -#endif - extern int setresuid(uid_t, uid_t, uid_t); #ifdef KERBEROS diff --git a/src/mom_rcp/util.c b/src/mom_rcp/util.c index 459dc36fa15..97fdec45c2d 100644 --- a/src/mom_rcp/util.c +++ b/src/mom_rcp/util.c @@ -31,10 +31,6 @@ * SUCH DAMAGE. */ -#ifndef lint -static const char sccsid[] = "@(#)util.c 8.2 (Berkeley) 4/2/94"; -#endif /* not lint */ - #include /* the master config generated by configure */ #include diff --git a/src/resmom/catch_child.c b/src/resmom/catch_child.c index 8012e61e825..cc7380be2bb 100644 --- a/src/resmom/catch_child.c +++ b/src/resmom/catch_child.c @@ -1658,10 +1658,10 @@ scan_for_exiting(void) */ if (stream == -1) { (void)kill_job(pjob, SIGKILL); - if ((pjob->ji_qs.ji_svrflags | - (JOB_SVFLG_CHKPT| - JOB_SVFLG_ChkptMig)) == 0) + if ((pjob->ji_qs.ji_svrflags & + (JOB_SVFLG_CHKPT | JOB_SVFLG_ChkptMig)) == 0) { mom_deljob(pjob); + } continue; } diff --git a/src/resmom/linux/mom_mach.c b/src/resmom/linux/mom_mach.c index 0e4fc1936b2..68491f20c95 100644 --- a/src/resmom/linux/mom_mach.c +++ b/src/resmom/linux/mom_mach.c @@ -5550,8 +5550,8 @@ mom_get_sample(void) { struct dirent *dent = NULL; FILE *fd = NULL; - static char path[1024]; - char procname[256]; + static char path[MAXPATHLEN + 1]; + char procname[384]; /* space for dent->d_name plus extra */ struct stat sb; proc_stat_t *ps = NULL; #if MOM_CPUSET @@ -5673,8 +5673,8 @@ mom_get_sample(void) } ps->start_time = linux_time + (starttime / hz); - memset(ps->comm, 0, COMSIZE); - strncpy(ps->comm, path, COMSIZE-1); + snprintf(ps->comm, sizeof(ps->comm), "%.*s", + (int)(sizeof(ps->comm) - 1), path); ps->utime = JTOS(ps->utime); ps->stime = JTOS(ps->stime); diff --git a/src/resmom/mom_hook_func.c b/src/resmom/mom_hook_func.c index 0c0258e0ae2..ea468f5710a 100644 --- a/src/resmom/mom_hook_func.c +++ b/src/resmom/mom_hook_func.c @@ -354,6 +354,7 @@ static void add_natural_vnode_info(vnl_t **p_vnlp) { char bufs[BUFSIZ]; + char *msgbuf; if (*p_vnlp == NULL) { if (vnl_alloc(p_vnlp) == NULL) { @@ -363,35 +364,34 @@ add_natural_vnode_info(vnl_t **p_vnlp) } snprintf(bufs, sizeof(bufs)-1, "%d", num_pcpus); - if (vn_addvnr(*p_vnlp, mom_short_name, ATTR_NODE_pcpus, bufs, - 0, 0, NULL) == -1) { - snprintf(log_buffer, sizeof(log_buffer), + if (vn_addvnr(*p_vnlp, mom_short_name, ATTR_NODE_pcpus, bufs, 0, 0, NULL) == -1) { + pbs_asprintf(&msgbuf, "Failed to add '%s %s=%s' to vnode list", mom_short_name, ATTR_NODE_pcpus, bufs); - log_err(-1, __func__, log_buffer); + log_err(-1, __func__, msgbuf); + free(msgbuf); return; } snprintf(bufs, sizeof(bufs)-1, "%d", num_acpus); - if (vn_addvnr(*p_vnlp, mom_short_name, "resources_available.ncpus", - bufs, 0, 0, NULL) == -1) { - snprintf(log_buffer, sizeof(log_buffer), + if (vn_addvnr(*p_vnlp, mom_short_name, "resources_available.ncpus", bufs, 0, 0, NULL) == -1) { + pbs_asprintf(&msgbuf, "Failed to add '%s %s=%s' to vnode list", - mom_short_name, "resources_available.ncpus", - bufs); - log_err(-1, __func__, log_buffer); + mom_short_name, "resources_available.ncpus", bufs); + log_err(-1, __func__, msgbuf); + free(msgbuf); return; } snprintf(bufs, sizeof(bufs)-1, "%llukb", av_phy_mem); - if (vn_addvnr(*p_vnlp, mom_short_name, "resources_available.mem", - bufs, 0, 0, NULL) == -1) { - snprintf(log_buffer, sizeof(log_buffer), + if (vn_addvnr(*p_vnlp, mom_short_name, "resources_available.mem", bufs, 0, 0, NULL) == -1) { + pbs_asprintf(&msgbuf, "Failed to add '%s %s=%s' to vnode list", mom_short_name, "resources_available.mem", bufs); - log_err(-1, __func__, log_buffer); + log_err(-1, __func__, msgbuf); + free(msgbuf); return; } @@ -400,8 +400,7 @@ add_natural_vnode_info(vnl_t **p_vnlp) arch(NULL), 0, 0, NULL) == -1) { snprintf(log_buffer, sizeof(log_buffer), "Failed to add '%s %s=%s' to vnode list", - mom_host, "arch", - arch(NULL)); + mom_host, "arch", arch(NULL)); log_err(-1, __func__, log_buffer); return; @@ -554,6 +553,7 @@ vnl_add_vnode_entries(vnl_t *vnl, vmpiprocs *vnode_entry, int num_vnodes, { int i, rc; char bufs[BUFSIZ]; + char *msgbuf; char *v_name = NULL; int v_cpus = 0; Long v_mem = 0; @@ -587,10 +587,10 @@ vnl_add_vnode_entries(vnl_t *vnl, vmpiprocs *vnode_entry, int num_vnodes, rc=vn_addvnr(vnl, v_name, RESCASSN_NCPUS, bufs, 0, 0, NULL); if (rc == -1) { - snprintf(log_buffer, sizeof(log_buffer), - "%s:failed to add '%s=%s'", + pbs_asprintf(&msgbuf, "%s:failed to add '%s=%s'", v_name, RESCASSN_NCPUS, bufs); - log_err(-1, __func__, log_buffer); + log_err(-1, __func__, msgbuf); + free(msgbuf); return (-1); } v_mem = vnode_entry[i].vn_mem; @@ -603,10 +603,10 @@ vnl_add_vnode_entries(vnl_t *vnl, vmpiprocs *vnode_entry, int num_vnodes, rc=vn_addvnr(vnl, v_name, RESCASSN_MEM, bufs, 0, 0, NULL); if (rc == -1) { - snprintf(log_buffer, sizeof(log_buffer), - "%s:failed add '%s=%s'", + pbs_asprintf(&msgbuf, "%s:failed add '%s=%s'", v_name, RESCASSN_MEM, bufs); - log_err(-1, __func__, log_buffer); + log_err(-1, __func__, msgbuf); + free(msgbuf); return (-1); } } @@ -694,6 +694,7 @@ run_hook(hook *phook, unsigned int event_type, mom_hook_input_t *hook_input, char *pc; int keeping = 0; char *std_file = NULL; + char *msgbuf; if ((phook == NULL) || (req_user == NULL) || (req_host == NULL)) { log_err(-1, __func__, "Bad input received!"); @@ -818,7 +819,8 @@ run_hook(hook *phook, unsigned int event_type, mom_hook_input_t *hook_input, /* replace with : */ /* must copy up to HOOK_SCRIPT_SUFFIX length so as to not */ /* overflow */ - strncpy(p, HOOK_CONFIG_SUFFIX, strlen(HOOK_SCRIPT_SUFFIX)); + snprintf(p, sizeof(hook_config_path) - (p - hook_config_path), + "%s", HOOK_SCRIPT_SUFFIX); if (stat(hook_config_path, &sbuf) != 0) { hook_config_path[0] = '\0'; } @@ -898,8 +900,8 @@ run_hook(hook *phook, unsigned int event_type, mom_hook_input_t *hook_input, } /* set hook_config_path to hook_config_copy */ /* if the copying was successful */ - strncpy(hook_config_path, hook_config_copy, - sizeof(hook_config_path)-1); + snprintf(hook_config_path, sizeof(hook_config_path), + "%s", hook_config_copy); } /* copy script_path to user-accessible */ /* [PBS_HOME]/path_spool */ @@ -1296,11 +1298,11 @@ run_hook(hook *phook, unsigned int event_type, mom_hook_input_t *hook_input, arg[11] = NULL; } - snprintf(log_buffer, sizeof(log_buffer), - "execve %s runas_jobuser=%d in child pid=%d", + pbs_asprintf(&msgbuf, "execve %s runas_jobuser=%d in child pid=%d", cmdline, runas_jobuser, myseq); log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_HOOK, LOG_INFO, - phook->hook_name, log_buffer); + phook->hook_name, msgbuf); + free(msgbuf); if (hook_config_path[0] == '\0') { #ifdef WIN32 @@ -1833,7 +1835,7 @@ get_hook_results(char *input_file, int *accept_flag, int *reject_flag, long int endpos; int start_new_vnl = 1; struct hook_vnl_action *pvna; - char hook_euser[PBS_MAXUSER+1]; + char hook_euser[PBS_MAXUSER+1] = {'\0'}; char *value_type = NULL; job *pjob2 = NULL; job *pjob2_prev = NULL; @@ -1849,7 +1851,6 @@ get_hook_results(char *input_file, int *accept_flag, int *reject_flag, /* copy of hook results, there will be one or more (one per hook) */ /* pbs_event().hook_euser= entries. In that case, hook_euser */ /* is reset to the . A null string means PBSADMIN. */ - hook_euser[0] = '\0'; if (phook && pjob && (phook->user == HOOK_PBSUSER)) { strncpy(hook_euser, pjob->ji_wattr[(int)JOB_ATR_euser].at_val.at_str, @@ -2494,7 +2495,8 @@ get_hook_results(char *input_file, int *accept_flag, int *reject_flag, pvna = malloc(sizeof(struct hook_vnl_action)); if ((pvna != NULL) && (pvnalist != NULL)) { CLEAR_LINK(pvna->hva_link); - strncpy(pvna->hva_euser, hook_euser, PBS_MAXUSER); + snprintf(pvna->hva_euser, sizeof(pvna->hva_euser), + "%s", hook_euser); pvna->hva_actid = 0; pvna->hva_vnl = NULL; if (vnl_alloc(&hvnlp) == NULL) { @@ -2728,7 +2730,7 @@ new_job_action_req(job *pjob, enum hook_user huser, int action) return; } CLEAR_LINK(phja->hja_link); - strncpy(phja->hja_jid, pjob->ji_qs.ji_jobid, PBS_MAXSVRJOBID); + snprintf(phja->hja_jid, sizeof(phja->hja_jid), "%s", pjob->ji_qs.ji_jobid); phja->hja_actid = ++hook_action_id; if (pjob->ji_wattr[(int)JOB_ATR_run_version].at_flags & ATR_VFLAG_SET) { diff --git a/src/resmom/mom_main.c b/src/resmom/mom_main.c index 849a6ae0dfc..add297fdcfe 100644 --- a/src/resmom/mom_main.c +++ b/src/resmom/mom_main.c @@ -2578,7 +2578,7 @@ do_mom_action_script(int ae, /* index into action table */ #ifdef WIN32 char buf[MAX_PATH + 1]; #else - char buf[_POSIX_PATH_MAX + 1]; + char buf[MAXPATHLEN + 1]; #endif int i; int nargs; @@ -8431,19 +8431,20 @@ main(int argc, char *argv[]) rlimit.rlim_cur = MIN_STACK_LIMIT; rlimit.rlim_max = MIN_STACK_LIMIT; if (setrlimit64(RLIMIT_STACK, &rlimit) == -1) { + char msgbuf[] = "Stack limit setting failed"; curerror = errno; - sprintf(log_buffer, "Stack limit setting failed"); - log_err(curerror, __func__, log_buffer); - sprintf(log_buffer, "%s errno=%d", log_buffer, curerror); + log_err(curerror, __func__, msgbuf); + sprintf(log_buffer, "%s errno=%d", msgbuf, curerror); log_record(PBSEVENT_ERROR, PBS_EVENTCLASS_SERVER, LOG_ERR, (char *)__func__, log_buffer); exit(1); } } } else { + char msgbuf[] = "Getting current Stack limit failed"; + curerror = errno; - sprintf(log_buffer, "Getting current Stack limit failed"); - log_err(curerror, __func__, log_buffer); - sprintf(log_buffer, "%s errno=%d", log_buffer, curerror); + log_err(curerror, __func__, msgbuf); + snprintf(log_buffer, sizeof(log_buffer), "%s errno=%d", msgbuf, curerror); log_record(PBSEVENT_ERROR, PBS_EVENTCLASS_SERVER, LOG_ERR, (char *)__func__, log_buffer); exit(1); } @@ -10495,18 +10496,16 @@ getkbdtime(void) { DIR *dp; struct dirent *de; - static char idle_dir[256]; - char idle_file[256]; + static char idle_dir[MAXPATHLEN + 1] = {'\0'}; + char *idle_file = NULL; struct input_dev_list *pl = &input_dev_list[0]; int i; int checked = 0; char *ptsname; - - /* since we call this function so often, only want to set this once */ if (idle_dir[0] == '\0') - sprintf(idle_dir, "%s/spool/idledir", pbs_conf.pbs_home_path); + snprintf(idle_dir, sizeof(idle_dir), "%s/spool/idledir", pbs_conf.pbs_home_path); if (check_idle_daemon) { if ((dp=opendir(idle_dir)) != NULL) { @@ -10517,9 +10516,10 @@ getkbdtime(void) break; if (*ptsname == '.') continue; - sprintf(idle_file, "%s/%s", idle_dir, ptsname); + pbs_asprintf(&idle_file, "%s/%s", idle_dir, ptsname); if (setmax(idle_file) > 0) checked = 1; + free(idle_file); } closedir(dp); } diff --git a/src/resmom/mom_vnode.c b/src/resmom/mom_vnode.c index 5bfb13dec86..0aa0429fc54 100644 --- a/src/resmom/mom_vnode.c +++ b/src/resmom/mom_vnode.c @@ -228,7 +228,7 @@ truncate_and_log(const char *id, char *buf, int bufsize) void mom_vnlp_report(vnl_t *vnl, char *header) { - int i, j, k; + int i; char reportbuf[LOG_BUF_SIZE+1]; char *p = NULL; vnl_t *vp; @@ -242,6 +242,7 @@ mom_vnlp_report(vnl_t *vnl, char *header) for (i = 0; i < vp->vnl_used; i++) { vnal_t *vnalp; + int j, k; vnalp = VNL_NODENUM(vp, i); bytes_left = LOG_BUF_SIZE; @@ -481,7 +482,7 @@ cpunum_free(unsigned int cpunum) assert(ret == AVL_EOIX); - sprintf(log_buffer, "CPU %d not found in cpuctx", cpunum); + sprintf(log_buffer, "CPU %u not found in cpuctx", cpunum); log_err(PBSE_SYSTEM, __func__, log_buffer); } } @@ -525,7 +526,7 @@ resadj(vnl_t *vp, const char *vnid, const char *res, enum res_op op, { int i, j; - sprintf(log_buffer, "vnode %s, resource %s, res_op %u, adjval %u", + sprintf(log_buffer, "vnode %s, resource %s, res_op %d, adjval %u", vnid, res, (int) op, adjval); log_event(PBSEVENT_DEBUG3, 0, LOG_DEBUG, __func__, log_buffer); for (i = 0; i < vp->vnl_used; i++) { @@ -535,12 +536,13 @@ resadj(vnl_t *vp, const char *vnid, const char *res, enum res_op op, if (strcmp(vnalp->vnal_id, vnid) != 0) continue; for (j = 0; j < vnalp->vnal_used; j++) { - vna_t *vnap; - unsigned int resval; - char valbuf[BUFSIZ]; + vna_t *vnap; vnap = VNAL_NODENUM(vnalp, j); if (strcmp(vnap->vna_name, res) == 0) { + unsigned int resval; + char valbuf[BUFSIZ]; + resval = strtoul(vnap->vna_val, NULL, 0); switch ((int) op) { case RES_DECR: @@ -553,7 +555,7 @@ resadj(vnl_t *vp, const char *vnid, const char *res, enum res_op op, resval = adjval; break; default: - sprintf(log_buffer, "unknown res_op %u", + sprintf(log_buffer, "unknown res_op %d", (int) op); log_event(PBSEVENT_ERROR, 0, LOG_ERR, __func__, log_buffer); @@ -658,61 +660,62 @@ cpu_inuse(unsigned int cpunum, job *pjob, int outofserviceflag) AVL_IX_DESC *pix; int ret; - if ((pix = cpuctx) != NULL) { - avl_first_key(pix); + pix = cpuctx; + if (pix == NULL) + return; + avl_first_key(pix); + + if (pe == NULL) { + pe = malloc(sizeof(AVL_IX_REC) + PBS_MAXNODENAME + 1); if (pe == NULL) { - pe = malloc(sizeof(AVL_IX_REC) + PBS_MAXNODENAME + 1); - if (pe == NULL) { - log_err(errno, __func__, "malloc pe failed"); - return; - } + log_err(errno, __func__, "malloc pe failed"); + return; } - while ((ret = avl_next_key(pe, pix)) == AVL_IX_OK) { - unsigned int i; - mominfo_t *mip; - mom_vninfo_t *mvp; - - mip = (mominfo_t *) pe->recptr; - assert(mip != NULL); - assert(mip->mi_data != NULL); + } + while ((ret = avl_next_key(pe, pix)) == AVL_IX_OK) { + unsigned int i; + mominfo_t *mip; + mom_vninfo_t *mvp; - mvp = (mom_vninfo_t *) mip->mi_data; - for (i = 0; i < mvp->mvi_ncpus; i++) - if (mvp->mvi_cpulist[i].mvic_cpunum == cpunum) { - if (MVIC_CPUISFREE(mvp, i)) { - cpuindex_inuse(mvp, i, pjob); - if (outofserviceflag != 0) { - assert(vnlp != NULL); - assert(mvp->mvi_id != NULL); - resadj(vnlp, mvp->mvi_id, - ra_ncpus, RES_DECR, - 1); - mvp->mvi_acpus--; - } + mip = (mominfo_t *) pe->recptr; + assert(mip != NULL); + assert(mip->mi_data != NULL); + + mvp = (mom_vninfo_t *) mip->mi_data; + for (i = 0; i < mvp->mvi_ncpus; i++) + if (mvp->mvi_cpulist[i].mvic_cpunum == cpunum) { + if (MVIC_CPUISFREE(mvp, i)) { + cpuindex_inuse(mvp, i, pjob); + if (outofserviceflag != 0) { + assert(vnlp != NULL); + assert(mvp->mvi_id != NULL); + resadj(vnlp, mvp->mvi_id, + ra_ncpus, RES_DECR, + 1); + mvp->mvi_acpus--; } - return; } - } + return; + } + } - assert(ret == AVL_EOIX); + assert(ret == AVL_EOIX); - /* - * If we get here, we didn't find the CPU in question. - * Requests to mark a CPU for which we have no record - * out of service may be benign; we may never have - * known about it because we were never told about it - * in a vnode definitions file, and the caller may - * simply not have checked first. So, we silently - * ignore those requests. However, if we're asked - * to mark a CPU in use but haven't heard of it, that's - * an error. - */ - if (outofserviceflag == 0) { - sprintf(log_buffer, "CPU %d not found in cpuctx", - cpunum); - log_err(PBSE_SYSTEM, __func__, log_buffer); - } + /* + * If we get here, we didn't find the CPU in question. + * Requests to mark a CPU for which we have no record + * out of service may be benign; we may never have + * known about it because we were never told about it + * in a vnode definitions file, and the caller may + * simply not have checked first. So, we silently + * ignore those requests. However, if we're asked + * to mark a CPU in use but haven't heard of it, that's + * an error. + */ + if (outofserviceflag == 0) { + sprintf(log_buffer, "CPU %u not found in cpuctx", cpunum); + log_err(PBSE_SYSTEM, __func__, log_buffer); } } @@ -1032,7 +1035,7 @@ new_vnid(const char *vnid, void *ctx) return NULL; } - strncpy(mip->mi_host, mom_host, sizeof(mip->mi_host)); + snprintf(mip->mi_host, sizeof(mip->mi_host), "%s", mom_host); mip->mi_port = pbs_mom_port; mip->mi_rmport = pbs_rm_port; mip->mi_data = mvp; diff --git a/src/resmom/requests.c b/src/resmom/requests.c index b5cba15d4f9..804ee85efb2 100644 --- a/src/resmom/requests.c +++ b/src/resmom/requests.c @@ -5112,8 +5112,8 @@ req_del_hookfile(struct batch_request *preq) /* ptr to the decoded request */ HOOK_SCRIPT_SUFFIX); } else { *p = '\0'; - strncpy(hook_name, preq->rq_ind.rq_hookfile.rq_filename, - MAXPATHLEN); + snprintf(hook_name, sizeof(hook_name), "%s", + preq->rq_ind.rq_hookfile.rq_filename); strcat(p, HOOK_FILE_SUFFIX); if ((phook = find_hook(hook_name)) != NULL) { delete_task_by_parm1(phook, DELETE_ONE); diff --git a/src/resmom/stage_func.c b/src/resmom/stage_func.c index 00604bd1a7e..972e1a39d2f 100644 --- a/src/resmom/stage_func.c +++ b/src/resmom/stage_func.c @@ -162,9 +162,9 @@ is_child_path(char *dir, char *path) /* if file path is relative, combine it with directory */ if (!is_full_path(path)) { - (void)snprintf(fullpath, sizeof(fullpath), "%s/%s", dir, path); + snprintf(fullpath, sizeof(fullpath), "%s/%s", dir, path); } else { - strncpy(fullpath, path, sizeof(fullpath)); + snprintf(fullpath, sizeof(fullpath), "%s", path); } dir_real = malloc(sizeof(char) * (MAXPATHLEN + 1)); diff --git a/src/resmom/start_exec.c b/src/resmom/start_exec.c index ddb012d976d..e2fefc55c4e 100644 --- a/src/resmom/start_exec.c +++ b/src/resmom/start_exec.c @@ -267,7 +267,6 @@ check_pwd(job *pjob) { struct passwd *pwdp; struct group *grpp; - char **pgnam; struct stat sb; pwdp = getpwnam(pjob->ji_wattr[(int)JOB_ATR_euser].at_val.at_str); @@ -314,6 +313,8 @@ check_pwd(job *pjob) return NULL; } if (grpp->gr_gid != pwdp->pw_gid) { + char **pgnam; + pgnam = grpp->gr_mem; while (*pgnam) { if (!strcmp(*pgnam, pwdp->pw_name)) @@ -356,11 +357,11 @@ ssize_t writepipe(int pfd, void *vptr, size_t nbytes) { size_t nleft; - ssize_t nwritten; char *ptr = vptr; /* so we can do pointer arithmetic */ nleft = nbytes; while (nleft > 0) { + ssize_t nwritten; nwritten = write(pfd, ptr, nleft); if (nwritten == -1) { if (errno == EINTR) @@ -393,11 +394,11 @@ ssize_t readpipe(int pfd, void *vptr, size_t nbytes) { size_t nleft; - ssize_t nread; char *ptr = vptr; /* so we can do pointer arithmetic */ nleft = nbytes; while (nleft > 0) { + ssize_t nread; nread = read(pfd, ptr, nleft); if (nread == -1) { if (errno == EINTR) @@ -782,8 +783,9 @@ mktmpdir(char *jobid, uid_t uid, gid_t gid, struct var_table *vtab) tmpdir = tmpdirname(jobid); errno = 0; - int tmp_errno; if (mkdir(tmpdir, 0700) == -1) { + int tmp_errno; + if ((tmp_errno = errno) != EEXIST) { sprintf(log_buffer, "mkdir: %s", tmpdir); log_joberr(tmp_errno, __func__, log_buffer, jobid); @@ -1032,8 +1034,11 @@ rmtmpdir(char *jobid) sprintf(rmdir, "%s/pbs_remove.%s", pbs_tmpdir, jobid); if (rename(tmpdir, newdir) == -1) { - sprintf(log_buffer, "%s %s", tmpdir, newdir); - log_joberr(errno, __func__, log_buffer, jobid); + char *msgbuf; + + pbs_asprintf(&msgbuf, "%s %s", tmpdir, newdir); + log_joberr(errno, __func__, msgbuf, jobid); + free(msgbuf); newdir = tmpdir; } @@ -1098,8 +1103,6 @@ int becomeuser_args(char *eusrname, uid_t euid, gid_t egid, gid_t rgid) { gid_t *grplist = NULL; - int i; - int numsup; static int maxgroups=0; /* obtain the maximum number of groups possible in the list */ @@ -1107,6 +1110,9 @@ becomeuser_args(char *eusrname, uid_t euid, gid_t egid, gid_t rgid) maxgroups = (int)sysconf(_SC_NGROUPS_MAX); if (initgroups(eusrname, egid) != -1) { + int numsup; + int i; + /* allocate an array for the group list */ grplist = calloc((size_t)maxgroups, sizeof(gid_t)); if (grplist == NULL) @@ -1338,7 +1344,8 @@ set_credential(job *pjob, char **shell, char ***argarray) } close(fd); - sprintf(buf, "FILE:%s", name_buf); + snprintf(buf, sizeof(buf), "FILE:%.*s", + (int)(sizeof(buf) - 6), name_buf); bld_env_variables(&vtable, "KRB5CCNAME", buf); sprintf(buf, "%s/sbin/pbs_renew", pbs_conf.pbs_exec_path); @@ -2044,7 +2051,6 @@ receive_pipe_request(int sd) job *pjob = NULL; pbs_task *ptask; int cmd; - char msg[LOG_BUF_SIZE]; if ((conn = get_conn(sd)) == NULL) { log_err(PBSE_INTERNAL, __func__, "unable to find pipe"); @@ -2081,6 +2087,8 @@ receive_pipe_request(int sd) log_err(-1, __func__, log_buffer); } } else { + char msg[LOG_BUF_SIZE]; + snprintf(msg, sizeof(msg), "ignoring unknown cmd %d", cmd); log_err(-1, __func__, msg); } @@ -2110,13 +2118,10 @@ finish_exec(job *pjob) int numthreads; attribute *pattr; attribute *pattri; - char *phost; #if SHELL_INVOKE == 1 int pipe_script[2] = {-1, -1}; #endif char *pts_name; /* name of slave pty */ - int pts; /* fd for slave pty */ - int qsub_sock, old_qsub_sock; char *shell; int jsmpipe[2] = {-1, -1}; /* job starter to MOM for sid */ int jsmpipe2[2] = {-1, -1}; /* job starter to MOM for sid */ @@ -2131,28 +2136,17 @@ finish_exec(job *pjob) #if MOM_ALPS struct startjob_rtn ack; #endif - char *termtype; pbs_task *ptask; struct array_strings *vstrs; struct sockaddr_in saddr; int nodemux = 0; char *pbs_jobdir; /* staging and execution directory of this job */ int sandbox_private = 0; - int display_number = 0, n = 0 , ret = 0; - char display[X_DISPLAY_LEN]; + int display_number = 0, n = 0; struct pfwdsock *socks = NULL; #ifdef NAS /* localmod 020 */ char * schedselect; #endif /* localmod 020 */ - char x11proto[X_DISPLAY_LEN], x11data[X_DISPLAY_LEN]; - char format[X_DISPLAY_LEN]; - char cmd[X_DISPLAY_LEN], x11authstr[X_DISPLAY_LEN]; - char auth_display[X_DISPLAY_LEN]; - char var[MAXPATHLEN+1]; - FILE *f; - unsigned int x11screen; - - char hook_msg[HOOK_MSG_SIZE+1]; int hook_rc; int prolo_hooks = 0;/*# of runnable prologue hooks*/ @@ -2468,13 +2462,13 @@ finish_exec(job *pjob) pjob->ji_qs.ji_un.ji_momt.ji_exgid); /* add escape in front of brackets */ - for (s=buf, d=holdbuf; *s; s++, d++) { + for (s = buf, d = holdbuf; *s && ((d - holdbuf) < sizeof(holdbuf)); s++, d++) { if (*s == '[' || *s == ']') *d++ = '\\'; *d = *s; } *d = '\0'; - strcpy(buf, holdbuf); + snprintf(buf, sizeof(buf), "%s", holdbuf); DBPRT(("shell: %s\n", buf)) #if SHELL_INVOKE == 1 if (is_interactive == 0) { @@ -2488,7 +2482,8 @@ finish_exec(job *pjob) /* if in "sandbox=PRIVATE" mode, prepend the script name on the pipe */ /* with "cd $PBS_JOBDIR;" command */ if (sandbox_private) { - sprintf(buf, "cd %s;%s", pbs_jobdir, holdbuf); + snprintf(buf, sizeof(buf), "cd %s;%.*s", pbs_jobdir, + (int)(sizeof(buf) - strlen(pbs_jobdir) - 5), holdbuf); } (void)strcat(buf, "\n"); /* setup above */ @@ -2662,7 +2657,7 @@ finish_exec(job *pjob) bld_env_variables(&vtable, variables_else[9], buf); /* PBS_MOMPORT */ - sprintf(buf, "%d", pbs_rm_port); + sprintf(buf, "%u", pbs_rm_port); bld_env_variables(&vtable, variables_else[10], buf); /* OMP_NUM_THREADS and NCPUS eq to number of cpus */ @@ -2761,7 +2756,12 @@ finish_exec(job *pjob) mom_unnice(); if (is_interactive) { - struct sigaction act; + struct sigaction act; + char *termtype; + char *phost; + int qsub_sock; + int old_qsub_sock; + int pts; /* fd for slave pty */ /*************************************************************************/ /* We have an "interactive" job, connect the standard */ @@ -2806,6 +2806,8 @@ finish_exec(job *pjob) FDMOVE(qsub_sock); if (pjob->ji_wattr[JOB_ATR_X11_cookie].at_val.at_str) { + char display[X_DISPLAY_LEN]; + if ((socks = calloc(sizeof(struct pfwdsock), NUM_SOCKS)) == NULL) { /* FAILURE - cannot alloc memory */ log_err(errno, __func__, "ERROR: could not calloc!\n"); @@ -3465,13 +3467,23 @@ finish_exec(job *pjob) starter_return(upfds, downfds, JOB_EXEC_OK, &sjr); log_close(0); - if ((pjob->ji_numnodes == 1) || nodemux || - ((cpid = fork()) > 0)) { /* parent does the shell */ + if ((pjob->ji_numnodes == 1) || nodemux || ((cpid = fork()) > 0)) { + /* parent does the shell */ + FILE *f; + /* close sockets that child uses */ (void)close(pjob->ji_stdout); (void)close(pjob->ji_stderr); if ((is_interactive == TRUE) && pjob->ji_wattr[JOB_ATR_X11_cookie].at_val.at_str) { + char auth_display[X_DISPLAY_LEN]; + char cmd[X_DISPLAY_LEN]; + char format[X_DISPLAY_LEN]; + char x11proto[X_DISPLAY_LEN]; + char x11data[X_DISPLAY_LEN]; + char x11authstr[X_DISPLAY_LEN]; + unsigned int x11screen; + int ret; x11proto[0] = x11data[0] = '\0'; format[0]='\0'; @@ -3500,7 +3512,7 @@ finish_exec(job *pjob) return; } ret = snprintf(auth_display, sizeof(auth_display), - "unix:%u.%u", + "unix:%d.%u", display_number, x11screen); if (ret >= sizeof(auth_display)) { @@ -3524,6 +3536,7 @@ finish_exec(job *pjob) return; } } else { + char var[MAXPATHLEN + 1]; sprintf(var, "%s/.Xauthority", pbs_jobdir); ret = snprintf(cmd, sizeof(cmd), "%s -f %s/.Xauthority -q -", @@ -4169,7 +4182,6 @@ void nodes_free(job *pj) { int i; - hnodent *np; vmpiprocs *vp; if (pj->ji_vnods) { @@ -4197,6 +4209,8 @@ nodes_free(job *pj) } if (pj->ji_hosts) { + hnodent *np; + np = pj->ji_hosts; for (i = 0; i < pj->ji_numnodes; i++, np++) { eventent *ep = (eventent *)GET_NEXT(np->hn_events); @@ -4276,9 +4290,6 @@ job_nodes_inner(struct job *pjob, hnodent **mynp) char momname[PBS_MAXNODENAME+1]; char momport[10] = {0}; int nmoms; - int nthreads; - int numprocs; - int found_cpus0; vmpiprocs *vmp; momvmap_t *pmm = NULL; mominfo_t *pmom; @@ -4472,6 +4483,10 @@ job_nodes_inner(struct job *pjob, hnodent **mynp) /* (1) parse chunk from select spec */ psubspec = parse_plus_spec_r(sbuf, &slast, &hpn); while (psubspec) { + int nthreads; + int numprocs; + int found_cpus0; + DBPRT(("\tsubspec: %s\n", psubspec)) nthreads = -1; numprocs = -1; @@ -4918,8 +4933,6 @@ job_nodes(struct job *pjob) return job_nodes_inner(pjob, NULL); } -#define NUMRAND (16/sizeof(long)) - /** * @brief * start_exec() - start execution of a job @@ -4929,20 +4942,16 @@ job_nodes(struct job *pjob) * @return Void * */ - void start_exec(job *pjob) { eventent *ep = NULL; - int com, i, nodenum; + int i, nodenum; pbs_socklen_t len; int socks[2]; struct sockaddr_in saddr; hnodent *np; - attribute *pattr; pbs_list_head phead; - int nodemux = 0; - int mtfd = -1; #if MOM_BGL int job_error_code; #endif/* MOM_BGL */ @@ -4964,30 +4973,34 @@ start_exec(job *pjob) return; } - /* make sure we have a cookie for the job */ + /* + * Ensure we have a cookie for the job. The cookie consists of a + * string of 32 hex characters plus a null terminator. The machine + * architecture needs to be considered when populating the string + * because random() and lrand48() return a long int. + */ if (!(pjob->ji_wattr[(int)JOB_ATR_Cookie].at_flags & ATR_VFLAG_SET)) { char *tt; int i; - int off = 2*sizeof(unsigned long); - tt = pjob->ji_wattr[(int)JOB_ATR_Cookie].at_val.at_str = - malloc(NUMRAND*off + 1); + tt = pjob->ji_wattr[(int)JOB_ATR_Cookie].at_val.at_str = malloc(33); if (tt == NULL) { log_joberr(ENOMEM, __func__, "out of memory", pjob->ji_qs.ji_jobid); exec_bail(pjob, JOB_EXEC_RETRY, NULL); return; } - pjob->ji_wattr[(int)JOB_ATR_Cookie].at_flags |=ATR_VFLAG_SET; + pjob->ji_wattr[(int)JOB_ATR_Cookie].at_flags |= ATR_VFLAG_SET; - for (i=0; iji_numnodes; if (nodenum > 1) { + attribute *pattr; + int nodemux = 0; + int mtfd = -1; + int com; + pjob->ji_resources = (noderes *)calloc(nodenum-1, sizeof(noderes)); assert(pjob->ji_resources != NULL); @@ -5352,7 +5370,6 @@ create_file_securely(char *path, uid_t exuid, gid_t exgid) char buf[MAXPATHLEN+1]; char *pc; mode_t cur_mask; - int acc; int fds; /* create a uniquely named file using mkstemp() */ @@ -5394,6 +5411,8 @@ create_file_securely(char *path, uid_t exuid, gid_t exgid) (void)unlink(buf); fds = -1; } else { + int acc; + /* add O_APPEND to the file descriptor so that lines */ /* written by qmsg are not overwritten by the job */ diff --git a/src/scheduler/check.c b/src/scheduler/check.c index 45ea4b04335..a1ab5a92575 100644 --- a/src/scheduler/check.c +++ b/src/scheduler/check.c @@ -1145,7 +1145,11 @@ check_avail_resources(schd_resource *reslist, resource_req *reqlist, char resbuf1[MAX_LOG_SIZE]; char resbuf2[MAX_LOG_SIZE]; char resbuf3[MAX_LOG_SIZE]; - char buf[MAX_LOG_SIZE]; + /* + * buf must be large enough to hold the three resbuf buffers plus a + * small amount of text... (R: resbuf1 A: resbuf2 T: resbuf3) + */ + char buf[(MAX_LOG_SIZE * 3) + 16]; if (reslist == NULL || reqlist == NULL) { if (perr != NULL) @@ -1224,7 +1228,8 @@ check_avail_resources(schd_resource *reslist, resource_req *reqlist, if (avail == SCHD_INFINITY && (flags & UNSET_RES_ZERO)) avail = 0; - /* if there is an infinite amount available or we are requesting + /* + * if there is an infinite amount available or we are requesting * 0 amount of the resource, we do not need to check if any is * available */ diff --git a/src/scheduler/fairshare.c b/src/scheduler/fairshare.c index e6edc072f5a..20a145a1d81 100644 --- a/src/scheduler/fairshare.c +++ b/src/scheduler/fairshare.c @@ -661,7 +661,7 @@ rec_write_usage(group_info *root, FILE *fp) #else if (root->usage != 1 && root->child == NULL && strcmp(root->name, UNKNOWN_GROUP_NAME) != 0) { #endif /* localmod 043 */ - strncpy(grp.name, root->name, USAGE_NAME_MAX); + snprintf(grp.name, sizeof(grp.name), "%s", root->name); grp.usage = root->usage; fwrite(&grp, sizeof(struct group_node_usage_v2), 1, fp); diff --git a/src/scheduler/fifo.c b/src/scheduler/fifo.c index 4f2bc7ff52d..4280281b5bd 100644 --- a/src/scheduler/fifo.c +++ b/src/scheduler/fifo.c @@ -263,7 +263,7 @@ update_cycle_status(struct status *policy, time_t current_time) enum prime_time prime; /* current prime time status */ struct tm *ptm; char logbuf[MAX_LOG_SIZE]; - char logbuf2[MAX_LOG_SIZE]; + char logbuf2[MAX_LOG_SIZE / 2]; struct tm *tmptr; if (policy == NULL) diff --git a/src/scheduler/job_info.c b/src/scheduler/job_info.c index e23d306d5cc..37a7645ab72 100644 --- a/src/scheduler/job_info.c +++ b/src/scheduler/job_info.c @@ -1563,35 +1563,41 @@ int send_attr_updates(int pbs_sd, char *job_name, struct attrl *pattr) { if (pbs_sd == SIMULATE_SD) return 1; /* simulation always successful */ + if (pattr->next == NULL) + one_attr = 1; - if (pattr->next == NULL) - one_attr = 1; + if (pbs_alterjob(pbs_sd, job_name, pattr, NULL) == 0) + return 1; - if (pbs_alterjob(pbs_sd, job_name, pattr, NULL) == 0) - return 1; - else { - if (is_finished_job(pbs_errno) == 1) { - if (one_attr) - snprintf(logbuf, MAX_LOG_SIZE, "Failed to update attr \'%s\' = %s, Job already finished", pattr->name, pattr->value); - else - snprintf(logbuf, MAX_LOG_SIZE, "Failed to update job attributes, Job already finished"); - schdlog(PBSEVENT_SCHED, PBS_EVENTCLASS_JOB, LOG_INFO, - job_name, logbuf); - return 0; - } - errbuf = pbs_geterrmsg(pbs_sd); - if (errbuf == NULL) - errbuf = ""; - if (one_attr) - snprintf(logbuf, MAX_LOG_SIZE, "Failed to update attr \'%s\' = %s: %s (%d)", pattr->name, pattr->value, errbuf, pbs_errno); + if (is_finished_job(pbs_errno) == 1) { + if (one_attr) + snprintf(logbuf, MAX_LOG_SIZE, + "Failed to update attr \'%s\' = %s, " + "Job already finished", + pattr->name, pattr->value); + else + snprintf(logbuf, MAX_LOG_SIZE, + "Failed to update job attributes, " + "Job already finished"); + schdlog(PBSEVENT_SCHED, PBS_EVENTCLASS_JOB, LOG_INFO, + job_name, logbuf); + return 0; + } - else - snprintf(logbuf, MAX_LOG_SIZE, "Failed to update job attributes: %s (%d)", errbuf, pbs_errno); + errbuf = pbs_geterrmsg(pbs_sd); + if (errbuf == NULL) + errbuf = ""; + if (one_attr) + snprintf(logbuf, MAX_LOG_SIZE, + "Failed to update attr \'%s\' = %s: %s (%d)", + pattr->name, pattr->value, errbuf, pbs_errno); + else + snprintf(logbuf, MAX_LOG_SIZE, + "Failed to update job attributes: %s (%d)", + errbuf, pbs_errno); - schdlog(PBSEVENT_SCHED, PBS_EVENTCLASS_SCHED, LOG_WARNING, - job_name, logbuf); - return 0; - } + schdlog(PBSEVENT_SCHED, PBS_EVENTCLASS_SCHED, LOG_WARNING, + job_name, logbuf); return 0; } @@ -1942,13 +1948,19 @@ translate_fail_code(schd_error *err, char *comment_msg, char *log_msg) switch (err->status_code) { case SCHD_UNKWN: case NOT_RUN: - snprintf(comment_msg, MAX_LOG_SIZE, "%s: %s", NOT_RUN_PREFIX, commentbuf); + snprintf(comment_msg, MAX_LOG_SIZE, "%s: %.*s", + NOT_RUN_PREFIX, + (int)(MAX_LOG_SIZE - strlen(NOT_RUN_PREFIX) - 3), + commentbuf); break; case NEVER_RUN: - snprintf(comment_msg, MAX_LOG_SIZE, "%s: %s", NEVER_RUN_PREFIX, commentbuf); + snprintf(comment_msg, MAX_LOG_SIZE, "%s: %.*s", + NEVER_RUN_PREFIX, + (int)(MAX_LOG_SIZE - strlen(NEVER_RUN_PREFIX) - 3), + commentbuf); break; default: - strcpy(comment_msg, commentbuf); + snprintf(comment_msg, MAX_LOG_SIZE, "%s", commentbuf); } } @@ -3048,8 +3060,8 @@ find_jobs_to_preempt(status *policy, resource_resv *hjob, server_info *sinfo, in resource_resv *pjob = NULL; int rc = 0; int retval = 0; - char buf[MAX_LOG_SIZE]; char log_buf[MAX_LOG_SIZE]; + char *msgbuf; nspec **ns_arr = NULL; schd_error *err = NULL; @@ -3149,9 +3161,10 @@ find_jobs_to_preempt(status *policy, resource_resv *hjob, server_info *sinfo, in cant_preempt = 1; if (cant_preempt) { translate_fail_code(cur_err, NULL, log_buf); - sprintf(buf, "Preempt: Can not preempt to run job: %s", log_buf); + pbs_asprintf(&msgbuf, "Preempt: Can not preempt to run job: %s", log_buf); schdlog(PBSEVENT_DEBUG, PBS_EVENTCLASS_JOB, - LOG_DEBUG, hjob->name, buf); + LOG_DEBUG, hjob->name, msgbuf); + free(msgbuf); free_schd_error_list(full_err); return NULL; } @@ -3386,9 +3399,10 @@ find_jobs_to_preempt(status *policy, resource_resv *hjob, server_info *sinfo, in } translate_fail_code(err, NULL, log_buf); - sprintf(buf, "Simulation: not enough work preempted: %s", log_buf); + pbs_asprintf(&msgbuf, "Simulation: not enough work preempted: %s", log_buf); schdlog(PBSEVENT_DEBUG2, PBS_EVENTCLASS_JOB, - LOG_DEBUG, njob->name, buf); + LOG_DEBUG, njob->name, msgbuf); + free(msgbuf); } pjobs[j] = NULL; diff --git a/src/scheduler/misc.c b/src/scheduler/misc.c index 3e3774ef376..aaea3adae03 100644 --- a/src/scheduler/misc.c +++ b/src/scheduler/misc.c @@ -440,7 +440,6 @@ schdlogerr(int event, int class, int sev, char *name, char *text, schd_error *err) { char logbuf[MAX_LOG_SIZE]; - char logbuf2[MAX_LOG_SIZE]; if (err == NULL) return; @@ -450,8 +449,11 @@ schdlogerr(int event, int class, int sev, char *name, char *text, if (text == NULL) schdlog(event, class, sev, name, logbuf); else { - snprintf(logbuf2, MAX_LOG_SIZE, "%s %s", text, logbuf); - schdlog(event, class, sev, name, logbuf2); + char *msgbuf; + + pbs_asprintf(&msgbuf, "%s %s", text, logbuf); + schdlog(event, class, sev, name, msgbuf); + free(msgbuf); } } } diff --git a/src/scheduler/node_info.c b/src/scheduler/node_info.c index b1839c3111c..b24e9ef55bf 100644 --- a/src/scheduler/node_info.c +++ b/src/scheduler/node_info.c @@ -2294,11 +2294,14 @@ eval_selspec(status *policy, selspec *spec, place *placespec, } } else { + char *msgbuf; + translate_fail_code(err, NULL, reason); - snprintf(logbuf, MAX_LOG_SIZE, - "Placement set %s is too small: %s", nodepart[i]->name, reason); + pbs_asprintf(&msgbuf, "Placement set %s is too small: %s", + nodepart[i]->name, reason); schdlog(PBSEVENT_DEBUG3, PBS_EVENTCLASS_JOB, LOG_DEBUG, - resresv->name, logbuf); + resresv->name, msgbuf); + free(msgbuf); set_schd_error_codes(err, NOT_RUN, SET_TOO_SMALL); set_schd_error_arg(err, ARG1, "Placement"); #ifdef NAS /* localmod 031 */ @@ -2382,6 +2385,7 @@ eval_placement(status *policy, selspec *spec, node_info **ninfo_arr, place *pl, nspec **ns_head = NULL; char logbuf[MAX_LOG_SIZE] = {0}; char reason[MAX_LOG_SIZE] = {0}; + char *msgbuf; resource_req *req = NULL; schd_resource *res = NULL; selspec *dselspec = NULL; @@ -2562,10 +2566,12 @@ eval_placement(status *policy, selspec *spec, node_info **ninfo_arr, place *pl, else translate_fail_code(err, NULL, reason); - snprintf(logbuf, MAX_LOG_SIZE, - "Insufficient host-level resources %s", reason); + pbs_asprintf(&msgbuf, + "Insufficient host-level resources %s", + reason); schdlog(PBSEVENT_DEBUG3, PBS_EVENTCLASS_JOB, LOG_DEBUG, - resresv->name, logbuf); + resresv->name, msgbuf); + free(msgbuf); if (failerr->status_code == SCHD_UNKWN) move_schd_error(failerr, err); clear_schd_error(err); @@ -2624,17 +2630,19 @@ eval_placement(status *policy, selspec *spec, node_info **ninfo_arr, place *pl, } } else { - if (hostsets[i]->free_nodes ==0) { + if (hostsets[i]->free_nodes == 0) { strncpy(reason, "No free nodes available", MAX_LOG_SIZE - 1); reason[MAX_LOG_SIZE - 1] = '\0'; } else translate_fail_code(err, NULL, reason); - snprintf(logbuf, MAX_LOG_SIZE, - "Insufficient host-level resources %s", reason); + pbs_asprintf(&msgbuf, + "Insufficient host-level resources %s", + reason); schdlog(PBSEVENT_DEBUG3, PBS_EVENTCLASS_JOB, LOG_DEBUG, - resresv->name, logbuf); + resresv->name, msgbuf); + free(msgbuf); if (failerr->status_code == SCHD_UNKWN) move_schd_error(failerr, err); @@ -2745,10 +2753,12 @@ eval_placement(status *policy, selspec *spec, node_info **ninfo_arr, place *pl, else translate_fail_code(err, NULL, reason); - snprintf(logbuf, MAX_LOG_SIZE, - "Insufficient host-level resources %s", reason); + pbs_asprintf(&msgbuf, + "Insufficient host-level resources %s", + reason); schdlog(PBSEVENT_DEBUG3, PBS_EVENTCLASS_JOB, LOG_DEBUG, - resresv->name, logbuf); + resresv->name, msgbuf); + free(msgbuf); #ifdef NAS /* localmod 998 */ set_schd_error_codes(err, NOT_RUN, RESOURCES_INSUFFICIENT); #else diff --git a/src/scheduler/parse.c b/src/scheduler/parse.c index dcf86c02414..49a6481fea5 100644 --- a/src/scheduler/parse.c +++ b/src/scheduler/parse.c @@ -102,7 +102,6 @@ parse_config(char *fname) int buf_size = 0; char logbuf[256]; /* used to write out log errors */ char buf2[8192]; /* general purpose buffer */ - char buf3[8192]; /* general purpose buffer */ char errbuf[1024]; /* buffer for reporting errors */ char *config_name; /* parse first word of line */ char *config_value; /* parsed second word - right after colen (:) */ @@ -172,34 +171,30 @@ parse_config(char *fname) config_value = scan(NULL, 0); prime_value = scan(NULL, 0); if (config_name != NULL && config_value != NULL) { - /* value is true */ - if (!strcmp(config_value, "true") || !strcmp(config_value, "True") - || !strncmp(config_value, "TRUE", 4)) { + if (strcasecmp(config_value, "true") == 0) { + /* value is true */ num = 1; - } - /* value is false */ - else if (!strcmp(config_value, "false") || - !strcmp(config_value, "False") || !strcmp(config_value, "FALSE")) { + } else if (strcasecmp(config_value, "false") == 0) { + /* value is false */ num = 0; - } - else if (isdigit((int) config_value[0])) { /* value is number */ + } else if (isdigit((int)config_value[0])) { + /* value is number */ num = strtol(config_value, &endp, 10); } - else ; /* value is a string */ - - if (prime_value != NULL) { - if (!strcmp(prime_value, "prime") || !strcmp(prime_value, "PRIME")) - prime = PRIME; - else if (!strcmp(prime_value, "non_prime") || - !strcmp(prime_value, "NON_PRIME")) - prime = NON_PRIME; - else if (!strcmp(prime_value, "all") || !strcmp(prime_value, "ALL")) - prime = ALL; - else if (!strcmp(prime_value, "none") || !strcmp(prime_value, "NONE")) - prime = NONE; - else - error = 1; - } + + if (prime_value != NULL) { + if (!strcmp(prime_value, "prime") || !strcmp(prime_value, "PRIME")) + prime = PRIME; + else if (!strcmp(prime_value, "non_prime") || + !strcmp(prime_value, "NON_PRIME")) + prime = NON_PRIME; + else if (!strcmp(prime_value, "all") || !strcmp(prime_value, "ALL")) + prime = ALL; + else if (!strcmp(prime_value, "none") || !strcmp(prime_value, "NONE")) + prime = NONE; + else + error = 1; + } if (!strcmp(config_name, PARSE_ROUND_ROBIN)) { if (prime == PRIME || prime == ALL) @@ -388,6 +383,7 @@ parse_config(char *fname) } } else if (!strcmp(config_name, PARSE_RESOURCES)) { + char *valbuf = NULL; buf2[0] = '\0'; /* hack: add in "host" into resources list because this was * done by default prior to 7.1. @@ -400,9 +396,8 @@ parse_config(char *fname) strcat(buf2, "vnode,"); if (buf2[0] != '\0') { - buf2[strlen(buf2)-1] = '\0'; - sprintf(buf3, "%s,%s", config_value, buf2); - config_value = buf3; + pbs_asprintf(&valbuf, "%s,%s", config_value, buf2); + config_value = valbuf; } conf.res_to_check = break_comma_list(config_value); @@ -411,6 +406,7 @@ parse_config(char *fname) ; conf.num_res_to_check = i; } + free(valbuf); } else if (!strcmp(config_name, PARSE_MOM_RESOURCES)) conf.dyn_res_to_get = break_comma_list(config_value); @@ -901,8 +897,11 @@ parse_config(char *fname) } if (error) { - sprintf(logbuf, "Error reading line %d: %s", linenum, errbuf); - schdlog(PBSEVENT_SCHED, PBS_EVENTCLASS_FILE, LOG_NOTICE, fname, logbuf); + char *msgbuf; + + pbs_asprintf(&msgbuf, "Error reading line %d: %s", linenum, errbuf); + schdlog(PBSEVENT_SCHED, PBS_EVENTCLASS_FILE, LOG_NOTICE, fname, msgbuf); + free(msgbuf); } if (obsolete[0] != NULL) { diff --git a/src/scheduler/pbs_sched.c b/src/scheduler/pbs_sched.c index 5015e7b48ab..b9a8207b75d 100644 --- a/src/scheduler/pbs_sched.c +++ b/src/scheduler/pbs_sched.c @@ -1098,19 +1098,19 @@ main(int argc, char *argv[]) rlimit.rlim_cur = MIN_STACK_LIMIT; rlimit.rlim_max = MIN_STACK_LIMIT; if (setrlimit(RLIMIT_STACK, &rlimit) == -1) { + char errmsg[] = "Stack limit setting failed"; curerror = errno; - sprintf(log_buffer, "Stack limit setting failed"); - log_err(curerror, __func__, log_buffer); - sprintf(log_buffer, "%s errno=%d", log_buffer, curerror); + log_err(curerror, __func__, errmsg); + sprintf(log_buffer, "%s errno=%d", errmsg, curerror); log_record(PBSEVENT_ERROR, PBS_EVENTCLASS_SERVER, LOG_ERR, (char *)__func__, log_buffer); exit(1); } } } else { + char errmsg[] = "Getting current Stack limit failed"; curerror = errno; - sprintf(log_buffer, "Getting current Stack limit failed"); - log_err(curerror, __func__, log_buffer); - sprintf(log_buffer, "%s errno=%d", log_buffer, curerror); + log_err(curerror, __func__, errmsg); + sprintf(log_buffer, "%s errno=%d", errmsg, curerror); log_record(PBSEVENT_ERROR, PBS_EVENTCLASS_SERVER, LOG_ERR, (char *)__func__, log_buffer); exit(1); } diff --git a/src/scheduler/resv_info.c b/src/scheduler/resv_info.c index 8e2190d8440..14d01a6c8ae 100644 --- a/src/scheduler/resv_info.c +++ b/src/scheduler/resv_info.c @@ -1223,8 +1223,8 @@ confirm_reservation(status *policy, int pbs_sd, resource_resv *unconf_resv, serv enum resv_conf rconf = RESV_CONFIRM_SUCCESS; /* assume reconf success */ char logmsg[MAX_LOG_SIZE]; char logmsg2[MAX_LOG_SIZE]; - char buf[MAX_LOG_SIZE]; char *errmsg; + char *msgbuf; nspec **ns = NULL; resource_resv *nresv = unconf_resv; @@ -1506,12 +1506,12 @@ confirm_reservation(status *policy, int pbs_sd, resource_resv *unconf_resv, serv (void) translate_fail_code(err, NULL, logmsg); /* If the reservation is degraded, we log a message and continue */ - snprintf(buf, MAX_LOG_SIZE, "Reservation Failed to Reconfirm: %s", - logmsg); + pbs_asprintf(&msgbuf, "Reservation Failed to Reconfirm: %s", logmsg); if (nresv->resv->resv_substate == RESV_DEGRADED) { schdlog(PBSEVENT_RESV, PBS_EVENTCLASS_RESV, LOG_INFO, - nresv->name, buf); + nresv->name, msgbuf); } + free(msgbuf); /* failed to confirm so move on. This will throw flow out of the * loop */ @@ -1570,13 +1570,13 @@ confirm_reservation(status *policy, int pbs_sd, resource_resv *unconf_resv, serv errmsg = ""; if (rconf == RESV_CONFIRM_FAIL) - snprintf(logmsg2, MAX_LOG_SIZE, "PBS Failed to confirm resv: %s", logmsg); + pbs_asprintf(&msgbuf, "PBS Failed to confirm resv: %s", errmsg); else { - snprintf(logmsg2, MAX_LOG_SIZE, "PBS Failed to confirm resv: %s (%d)", errmsg, pbs_errno); + pbs_asprintf(&msgbuf, "PBS Failed to confirm resv: %s (%d)", errmsg, pbs_errno); rconf = RESV_CONFIRM_RETRY; } - schdlog(PBSEVENT_RESV, PBS_EVENTCLASS_RESV, LOG_INFO, nresv_parent->name, - logmsg2); + schdlog(PBSEVENT_RESV, PBS_EVENTCLASS_RESV, LOG_INFO, nresv_parent->name, msgbuf); + free(msgbuf); if (nresv_parent->resv->resv_substate == RESV_DEGRADED) { snprintf(logmsg, MAX_LOG_SIZE, "Reservation is in degraded mode, %d out of %d vnodes are unavailable; %s", diff --git a/src/scheduler/simulate.c b/src/scheduler/simulate.c index c1fb0be1518..ccd7d6110a7 100644 --- a/src/scheduler/simulate.c +++ b/src/scheduler/simulate.c @@ -537,7 +537,6 @@ int perform_event(status *policy, timed_event *event) { char logbuf[MAX_LOG_SIZE]; - char logbuf2[MAX_LOG_SIZE]; char timebuf[128]; resource_resv *resresv; int ret = 1; @@ -592,9 +591,12 @@ perform_event(status *policy, timed_event *event) event->event_func(event->event_ptr, event->event_func_arg); if (ret) { - snprintf(logbuf2, MAX_LOG_SIZE, "Simulation: %s [%s]", logbuf, timebuf); + char *msgbuf; + + pbs_asprintf(&msgbuf, "Simulation: %s [%s]", logbuf, timebuf); schdlog(PBSEVENT_DEBUG3, PBS_EVENTCLASS_JOB, LOG_DEBUG, - event->name, logbuf2); + event->name, msgbuf); + free(msgbuf); } return ret; } diff --git a/src/scheduler/site_code.c b/src/scheduler/site_code.c index 4864b32609d..a13400e4dd6 100644 --- a/src/scheduler/site_code.c +++ b/src/scheduler/site_code.c @@ -4,8 +4,6 @@ *===================================================================== */ -static const char ident[] = "$Id: site_code.c,v 1.56 2016/04/19 00:10:27 dtalcott Exp $"; - #include #include @@ -199,7 +197,6 @@ site_check_cpu_share(server_info *sinfo, status *policy, resource_resv *resv) job_info *job; share_head *sh; /* global share totals */ timed_event *te; - resource_resv *te_rr; long time_left, end; unsigned int event_mask; @@ -250,6 +247,9 @@ site_check_cpu_share(server_info *sinfo, status *policy, resource_resv *resv) for (te = find_init_timed_event(te, IGNORE_DISABLED_EVENTS, event_mask); te != NULL && te->event_time < end; te = find_next_timed_event(te, IGNORE_DISABLED_EVENTS, event_mask)) { + + resource_resv *te_rr; + te_rr = (resource_resv *) te->event_ptr; if (te_rr == resv) continue; /* Should not happen */ @@ -293,7 +293,6 @@ check_cpu_share(share_head *sh, resource_resv *resv) share_info *leader; /* info for group leader */ int sh_cls; /* current share class */ sh_amt *job_amts; /* amounts requested by job */ - int asking, limited, borrowed, allocated; if (sh == NULL || resv == NULL) return rc; @@ -312,7 +311,10 @@ check_cpu_share(share_head *sh, resource_resv *resv) * none */ for (sh_cls = 0; sh_cls < shr_class_count ; ++sh_cls) { + int limited, borrowed, allocated; + int asking; int rc2 = 0; + asking = job_amts[sh_cls]; #if NAS_CPU_MULT > 1 if (asking % NAS_CPU_MULT) { @@ -766,7 +768,6 @@ void site_list_shares(FILE *fp, server_info *sinfo, const char *pfx, int flag) { share_info *root; - char *sname; int idx; if (fp == NULL || sinfo == NULL || sinfo->share_head == NULL @@ -774,6 +775,8 @@ site_list_shares(FILE *fp, server_info *sinfo, const char *pfx, int flag) return; } for (idx = 0; idx < shr_class_count ; ++idx) { + char *sname; + sname = shr_class_name_by_idx(idx); list_share_info(fp, root, pfx, idx, sname, flag); } @@ -799,7 +802,6 @@ site_list_jobs(server_info *sinfo, resource_resv **rarray) sh_amt *job_amts; char *sname; char *starving; - static char whoami[] = "site_list_jobs" ; fname = SORTED_FILE; sj = fopen(fname, "w+"); @@ -807,7 +809,7 @@ site_list_jobs(server_info *sinfo, resource_resv **rarray) sprintf(log_buffer, "Cannot open %s: %s\n", fname, strerror(errno)); schdlog(PBSEVENT_SCHED, PBS_EVENTCLASS_JOB, LOG_ERR, - whoami, log_buffer); + __func__, log_buffer); return; } site_list_shares(sj, sinfo, "#A ", 0); @@ -900,7 +902,6 @@ site_parse_shares(char *fname) sh_amt *tshares; /* temp shares values */ struct shr_class *tclass; /* temp class pointer */ struct shr_type *ttype; /* temp type pointer */ - char *whoami = "site_parse_shares"; int new_cls_cnt; /* number of CPU classes */ int new_type_cnt; /* number of CPU types */ struct shr_class *new_shr_clses; /* new class list */ @@ -922,7 +923,7 @@ site_parse_shares(char *fname) if ((fp = fopen(fname, "r")) == NULL) { i = errno; sprintf(log_buffer, "Error opening file %s", fname); - log_err(i, whoami, log_buffer); + log_err(i, __func__, log_buffer); return 1; /* continue without shares */ } while (fgets(buf, LINE_BUF_SIZE, fp) != NULL) { @@ -1255,7 +1256,7 @@ site_parse_shares(char *fname) continue; /* Done with line */ err_parse: schdlog(PBSEVENT_SCHED, PBS_EVENTCLASS_FILE, LOG_NOTICE, - whoami, log_buffer); + __func__, log_buffer); if (cur) { free(cur); } @@ -1314,8 +1315,8 @@ site_parse_shares(char *fname) return 1; err_out_l: - log_err(-1, whoami, log_buffer); - schdlog(PBSEVENT_SCHED, PBS_EVENTCLASS_FILE, LOG_NOTICE, whoami, + log_err(-1, __func__, log_buffer); + schdlog(PBSEVENT_SCHED, PBS_EVENTCLASS_FILE, LOG_NOTICE, __func__, "Warning: CPU shares file parse error: file ignored"); for (ttype = new_shr_types; ttype; ttype = new_shr_types) { new_shr_types = ttype->next; @@ -1465,7 +1466,6 @@ site_resort_jobs(resource_resv *njob) { server_info *sinfo; queue_info *queue; - resource_resv *resv; job_info *job; int i; @@ -1476,6 +1476,8 @@ site_resort_jobs(resource_resv *njob) * Update values that changed due to job starting. */ for (i = 0; i < sinfo->sc.total; ++i) { + resource_resv *resv; + resv = sinfo->jobs[i]; if (!resv->is_job || !in_runnable_state(resv)) continue; @@ -1548,10 +1550,8 @@ site_set_job_share(resource_resv *resresv) chunk * chunk; int i; job_info * job; - int ncpus; resource_req * preq; selspec * select; - int sh_cls; sh_amt * sh_amts; struct shr_type * stp; @@ -1569,8 +1569,12 @@ site_set_job_share(resource_resv *resresv) } memset(sh_amts, 0, shr_class_count * sizeof(*sh_amts)); for (i = 0; (chunk = select->chunks[i]) != NULL; ++i) { + int ncpus; + int sh_cls; + ncpus = 0; stp = NULL; + for (preq = chunk->req; preq != NULL; preq = preq->next) { if (strcmp(preq->name, shr_selector) == 0) { stp = shr_type_info_by_name(preq->res_str); @@ -1915,7 +1919,6 @@ site_update_on_end(server_info *sinfo, queue_info *qinfo, resource_resv *resv) share_info *si; sh_amt *sc; share_head *shead; - int i, ncpus, borrowed; if (sinfo == NULL || (shead = sinfo->share_head) == NULL) return; @@ -1928,13 +1931,17 @@ site_update_on_end(server_info *sinfo, queue_info *qinfo, resource_resv *resv) if ((si = si->leader) == NULL) return; if (resv->share_type != J_TYPE_ignore) { + int i; + for (i = 0; i < shr_class_count; ++i) { + int borrowed; + int ncpus; + ncpus = sc[i]; shead->sh_avail[i] += ncpus; - borrowed = \ - si->share_inuse[i][J_TYPE_limited] - +si->share_inuse[i][J_TYPE_borrow] - -si->share_ncpus[i]; + borrowed = si->share_inuse[i][J_TYPE_limited] + + si->share_inuse[i][J_TYPE_borrow] - + si->share_ncpus[i]; if (borrowed > 0) { if (borrowed > ncpus) borrowed = ncpus; @@ -2177,7 +2184,6 @@ static void count_cpus(node_info **nodes, int ncnt, queue_info **queues, sh_amt *totals) { int i; - node_info *node; resource *res; sch_resource_t ncpus; @@ -2185,6 +2191,8 @@ count_cpus(node_info **nodes, int ncnt, queue_info **queues, sh_amt *totals) totals[i] = 0; } for (i = 0; i < ncnt; ++i) { + node_info *node; + node = nodes[i]; /* * Skip nodes in unusable states. @@ -2252,11 +2260,12 @@ static void count_active_cpus(resource_resv **resvs, int jcnt, sh_amt *sh_active) { int i, k; - job_info *job; resource_resv *resv; memset(sh_active, 0, shr_class_count * sizeof(*sh_active)); for (i = 0; i < jcnt; ++i) { + job_info *job; + /* * Skip everything but running jobs */ @@ -2327,7 +2336,7 @@ count_demand_cpus(resource_resv **resvs, int jcnt) static void count_contrib_cpus(share_info *root, share_info *node, sh_amt *sh_contrib) { - int i, j; + int i; int contrib; if (root == NULL || node == NULL) @@ -2360,6 +2369,8 @@ count_contrib_cpus(share_info *root, share_info *node, sh_amt *sh_contrib) * Remove root demand from amounts available. */ for (i = 0; i < shr_class_count; ++i) { + int j; + contrib = sh_contrib[i]; for (j = 0; j < J_TYPE_COUNT; ++j) { if (j != J_TYPE_borrow) { @@ -2848,21 +2859,24 @@ init_users(server_info *sinfo) static void list_share_info(FILE *fp, share_info *root, const char *pfx, int idx, const char *sname, int flag) { - char buf[J_TYPE_COUNT * 2 * 15]; - char *p; - char *s; - char *lname; - int j, len; - sh_amt *use_amts; - sh_amt *dmd_amts; if (shr_types == NULL || shr_class_count == 0) return; if (flag == 0 || root == root->leader) { + char buf[J_TYPE_COUNT * 2 * 15]; + char *p; + char *s; + char *lname; + int j; + sh_amt *use_amts; + sh_amt *dmd_amts; + use_amts = &root->share_inuse[idx][0]; dmd_amts = &root->share_demand[idx][0]; s = ""; p = buf; for (j = 0; j < J_TYPE_COUNT; ++j) { + int len; + len = sprintf(p, "%s%d+%d", s, use_amts[j], dmd_amts[j]); p += len; @@ -2894,10 +2908,7 @@ list_share_info(FILE *fp, share_info *root, const char *pfx, int idx, const char static void set_share_cpus(share_info *node, sh_amt *gross, sh_amt *sh_avail) { - int cpus; - double t_shares, t_cpus; int i; - static char whoami[] = "set_share_cpus"; if (node == NULL) return; @@ -2905,10 +2916,12 @@ set_share_cpus(share_info *node, sh_amt *gross, sh_amt *sh_avail) * Only groups with allocations get ncpus set */ if (node->share_gross[0] >= 0) { + int cpus; for (i = 0; i < shr_class_count; ++i) { if (node->share_net[i] == 0) { cpus = 0; } else { + double t_shares, t_cpus; t_cpus = sh_avail[i]; t_shares = gross[i]; /* @@ -2919,7 +2932,7 @@ set_share_cpus(share_info *node, sh_amt *gross, sh_amt *sh_avail) t_shares); if (cpus < 4) { printf("%s: group %s gets only %d %s CPUs\n", - whoami, node->name, + __func__, node->name, cpus, shr_class_name_by_idx(i)); fflush(stdout); } @@ -3200,8 +3213,6 @@ reconcile_share_tree(share_info *root, share_info *def, int cnt) { share_info *child; int i; - sh_amt c_sum, gross; - static char whoami[] = "reconcile_share_tree"; if (root == NULL || def == NULL) return 1; @@ -3237,6 +3248,8 @@ reconcile_share_tree(share_info *root, share_info *def, int cnt) */ if (def == root) { for (i = 0; i < cnt; ++i) { + sh_amt c_sum, gross; + gross = root->share_gross[i]; c_sum = root->share_net[i]; if (c_sum > gross) { @@ -3246,7 +3259,7 @@ reconcile_share_tree(share_info *root, share_info *def, int cnt) root->name, shr_class_name_by_idx(i), gross, c_sum); schdlog(PBSEVENT_SCHED, PBS_EVENTCLASS_FILE, - LOG_NOTICE, whoami, log_buffer); + LOG_NOTICE, __func__, log_buffer); } root->share_gross[i] = gross = c_sum; } @@ -3529,9 +3542,6 @@ pick_next_job(status *policy, resource_resv **jobs, pick_next_filter pnfilter, s resource_resv *good = NULL; /* job with the min usage / percentage */ int cmp; /* comparison value of two jobs */ int i; -#if NAS_DEBUG - char *whoami = "pick_next_job"; -#endif /* NAS_DEBUG */ if (policy == NULL || jobs == NULL || pnfilter == NULL) return NULL; @@ -3553,7 +3563,7 @@ pick_next_job(status *policy, resource_resv **jobs, pick_next_filter pnfilter, s if (multi_sort(good, jobs[i]) != 0) { #if NAS_DEBUG printf("%s: stopped at %s vs. %s\n", - whoami, good->name, jobs[i]->name); + __func__, good->name, jobs[i]->name); fflush(stdout); #endif break; diff --git a/src/server/hook_func.c b/src/server/hook_func.c index 1b484562bce..b6d26b7efa1 100644 --- a/src/server/hook_func.c +++ b/src/server/hook_func.c @@ -172,8 +172,7 @@ static pid_t g_sync_hook_pid = -1; /* pid of the child sync_mom_hookfiles() proc /* process sending out mom hook files */ static unsigned long hook_rescdef_checksum = 0; -/* mom hook action(s) to keep */ -/* track */ +/* mom hook action(s) to keep track */ #define GROW_MOMHOOK_ARRAY_AMT 10 #define CONN_RETRY 3 @@ -460,7 +459,7 @@ send_rescdef(int force) struct stat sbuf2; if (mom_hooks_seen <= 0) { - if (mom_hooks_seen < 0) { /* should not happen */ + if (mom_hooks_seen < 0) { /* should not happen */ log_event(PBSEVENT_DEBUG2, PBS_EVENTCLASS_HOOK, LOG_INFO, __func__, "mom_hooks_seen went negative, resetting to 0"); @@ -789,7 +788,7 @@ mgr_hook_create(struct batch_request *preq) svrattrl *plist, *plx; hook *phook = NULL; hook *phook2 = NULL; - char hook_msg[HOOK_MSG_SIZE]; + char hook_msg[HOOK_MSG_SIZE] = {'\0'}; char *hook_user_val = NULL; char *hook_fail_action_val = NULL; char *hook_freq_val = NULL; @@ -799,15 +798,13 @@ mgr_hook_create(struct batch_request *preq) return; } - memset(hook_msg, '\0', HOOK_MSG_SIZE); - if ((phook2=find_hook(preq->rq_ind.rq_manager.rq_objname)) != NULL) { if (phook2->pending_delete) { - snprintf(hook_msg, HOOK_MSG_SIZE-1, + snprintf(hook_msg, sizeof(hook_msg), "hook name \'%s\' is pending delete, try another name", preq->rq_ind.rq_manager.rq_objname); } else { - snprintf(hook_msg, HOOK_MSG_SIZE-1, + snprintf(hook_msg, sizeof(hook_msg), "hook name \'%s\' already registered, try another name", preq->rq_ind.rq_manager.rq_objname); } @@ -850,7 +847,7 @@ mgr_hook_create(struct batch_request *preq) free(hook_user_val); hook_user_val = strdup(plx->al_value); if (hook_user_val == NULL) { - snprintf(hook_msg, HOOK_MSG_SIZE-1, + snprintf(hook_msg, sizeof(hook_msg), "strdup(%s) failed: errno %d", plx->al_value, errno); goto mgr_hook_create_error; @@ -864,7 +861,7 @@ mgr_hook_create(struct batch_request *preq) free(hook_fail_action_val); hook_fail_action_val = strdup(plx->al_value); if (hook_fail_action_val == NULL) { - snprintf(hook_msg, HOOK_MSG_SIZE-1, + snprintf(hook_msg, sizeof(hook_msg), "strdup(%s) failed: errno %d", plx->al_value, errno); goto mgr_hook_create_error; @@ -890,7 +887,7 @@ mgr_hook_create(struct batch_request *preq) free(hook_freq_val); hook_freq_val = strdup(plx->al_value); if (hook_freq_val == NULL) { - snprintf(hook_msg, HOOK_MSG_SIZE-1, + snprintf(hook_msg, sizeof(hook_msg), "strdup(%s) failed: errno %d", plx->al_value, errno); goto mgr_hook_create_error; @@ -934,7 +931,7 @@ mgr_hook_create(struct batch_request *preq) preq->rq_ind.rq_manager.rq_objname, log_buffer); if (hook_save(phook) != 0) { - snprintf(hook_msg, HOOK_MSG_SIZE-1, + snprintf(hook_msg, sizeof(hook_msg), "Failed to store '%s' permanently.", preq->rq_ind.rq_manager.rq_objname); goto mgr_hook_create_error; @@ -984,22 +981,20 @@ mgr_hook_delete(struct batch_request *preq) hook *phook = NULL; - char hookname[PBS_MAXSVRJOBID + 1] = {0}; - char hook_msg[HOOK_MSG_SIZE] = {0}; - - memset(hook_msg, '\0', HOOK_MSG_SIZE); + char hookname[PBS_MAXSVRJOBID + 1] = {'\0'}; + char hook_msg[HOOK_MSG_SIZE] = {'\0'}; if (strlen(preq->rq_ind.rq_manager.rq_objname) == 0) { reply_text(preq, PBSE_HOOKERROR, "no hook name specified"); return; } - strncpy(hookname, preq->rq_ind.rq_manager.rq_objname, PBS_MAXSVRJOBID); + snprintf(hookname, sizeof(hookname), "%s", preq->rq_ind.rq_manager.rq_objname); phook = find_hook(hookname); if ((phook == NULL) || phook->pending_delete) { - snprintf(hook_msg, HOOK_MSG_SIZE-1, "%s does not exist!", + snprintf(hook_msg, sizeof(hook_msg), "%s does not exist!", hookname); log_event(PBSEVENT_ADMIN, PBS_EVENTCLASS_HOOK, LOG_INFO, hookname, hook_msg); @@ -1033,7 +1028,7 @@ mgr_hook_delete(struct batch_request *preq) log_event(PBSEVENT_ADMIN, PBS_EVENTCLASS_HOOK, LOG_INFO, hookname, hook_msg); if (hook_save(phook) != 0) { - snprintf(hook_msg, HOOK_MSG_SIZE-1, + snprintf(hook_msg, sizeof(hook_msg), "Warning: failed to store '%s' permanently.", preq->rq_ind.rq_manager.rq_objname); log_event(PBSEVENT_ADMIN, PBS_EVENTCLASS_HOOK, LOG_INFO, @@ -1129,16 +1124,17 @@ void mgr_hook_import(struct batch_request *preq) { svrattrl *plist, *plx; - char hookname[PBS_MAXSVRJOBID + 1] = {0}; + char hookname[PBS_MAXSVRJOBID + 1] = {'\0'}; hook *phook; char content_type[BUFSIZ]; char content_encoding[BUFSIZ]; char input_file[MAXPATHLEN + 1]; char input_file_path[MAXPATHLEN + 1]; - char input_path[MAXPATHLEN + 1] = {0}; + char input_path[MAXPATHLEN + 1] = {'\0'}; char temp_path[MAXPATHLEN + 1]; - char output_path[MAXPATHLEN + 1] = {0}; - char hook_msg[HOOK_MSG_SIZE] = {0}; + char output_path[MAXPATHLEN + 1] = {'\0'}; + char msgbuf[HOOK_MSG_SIZE]; + char *hook_msg = NULL; int overwrite; struct python_script *py_test_script = NULL; int rc; @@ -1151,14 +1147,15 @@ mgr_hook_import(struct batch_request *preq) return; } - strncpy(hookname, preq->rq_ind.rq_manager.rq_objname, PBS_MAXSVRJOBID); + snprintf(hookname, sizeof(hookname), "%s", preq->rq_ind.rq_manager.rq_objname); phook = find_hook(hookname); if ((phook == NULL) || phook->pending_delete) { - snprintf(hook_msg, HOOK_MSG_SIZE, "%s does not exist!", hookname); + pbs_asprintf(&hook_msg, "%s does not exist!", hookname); log_event(PBSEVENT_ADMIN, PBS_EVENTCLASS_HOOK, LOG_INFO, hookname, hook_msg); reply_text(preq, PBSE_HOOKERROR, hook_msg); + free(hook_msg); return; } @@ -1166,18 +1163,20 @@ mgr_hook_import(struct batch_request *preq) /* But HOOK_PBS hooks can also be shown if the qmgr request is */ /* specifically operating on the "pbshook" keyword. */ if ((phook->type != HOOK_SITE) && (hook_obj != MGR_OBJ_PBS_HOOK)) { - snprintf(hook_msg, HOOK_MSG_SIZE, "%s not of '%s' type", hookname, HOOKSTR_SITE); + pbs_asprintf(&hook_msg, "%s not of '%s' type", hookname, HOOKSTR_SITE); log_event(PBSEVENT_ADMIN, PBS_EVENTCLASS_HOOK, LOG_INFO, hookname, hook_msg); reply_text(preq, PBSE_HOOKERROR, hook_msg); + free(hook_msg); return; } /* Cannot show a HOOK_SITE hook if the qmgr request keyword is */ /* "pbshook" */ if ((phook->type == HOOK_SITE) && (hook_obj == MGR_OBJ_PBS_HOOK)) { - snprintf(hook_msg, HOOK_MSG_SIZE, "%s not of '%s' type", hookname, HOOKSTR_PBS); + pbs_asprintf(&hook_msg, "%s not of '%s' type", hookname, HOOKSTR_PBS); log_event(PBSEVENT_ADMIN, PBS_EVENTCLASS_HOOK, LOG_INFO, hookname, hook_msg); reply_text(preq, PBSE_HOOKERROR, hook_msg); + free(hook_msg); return; } @@ -1194,22 +1193,19 @@ mgr_hook_import(struct batch_request *preq) if (strcasecmp(plx->al_name, CONTENT_TYPE_PARAM) == 0) { if (plx->al_value == NULL) { - snprintf(hook_msg, HOOK_MSG_SIZE, - "<%s> is NULL", CONTENT_TYPE_PARAM); + pbs_asprintf(&hook_msg, "<%s> is NULL", + CONTENT_TYPE_PARAM); goto mgr_hook_import_error; } if (hook_obj == MGR_OBJ_PBS_HOOK) { if (strcmp(plx->al_value, HOOKSTR_CONFIG) != 0) { - snprintf(hook_msg, HOOK_MSG_SIZE, - "<%s> must be %s", + pbs_asprintf(&hook_msg, "<%s> must be %s", CONTENT_TYPE_PARAM, HOOKSTR_CONFIG); goto mgr_hook_import_error; } } else if ((strcmp(plx->al_value, HOOKSTR_CONTENT) != 0) && - (strcmp(plx->al_value, HOOKSTR_CONFIG) != 0)) { - - snprintf(hook_msg, HOOK_MSG_SIZE, - "<%s> must be %s or %s", + (strcmp(plx->al_value, HOOKSTR_CONFIG) != 0)) { + pbs_asprintf(&hook_msg, "<%s> must be %s or %s", CONTENT_TYPE_PARAM, HOOKSTR_CONTENT, HOOKSTR_CONFIG); goto mgr_hook_import_error; } @@ -1217,14 +1213,13 @@ mgr_hook_import(struct batch_request *preq) } else if (strcasecmp(plx->al_name, CONTENT_ENCODING_PARAM) == 0) { if (plx->al_value == NULL) { - snprintf(hook_msg, HOOK_MSG_SIZE, - "<%s> is NULL", CONTENT_ENCODING_PARAM); + pbs_asprintf(&hook_msg, "<%s> is NULL", + CONTENT_ENCODING_PARAM); goto mgr_hook_import_error; } if ((strcmp(plx->al_value, HOOKSTR_DEFAULT) != 0) && - (strcmp(plx->al_value, HOOKSTR_BASE64) != 0)) { - snprintf(hook_msg, HOOK_MSG_SIZE, - "<%s> must be '%s' or '%s'", + (strcmp(plx->al_value, HOOKSTR_BASE64) != 0)) { + pbs_asprintf(&hook_msg, "<%s> must be '%s' or '%s'", CONTENT_ENCODING_PARAM, HOOKSTR_DEFAULT, HOOKSTR_BASE64); goto mgr_hook_import_error; @@ -1232,21 +1227,18 @@ mgr_hook_import(struct batch_request *preq) strcpy(content_encoding, plx->al_value); } else if (strcasecmp(plx->al_name, INPUT_FILE_PARAM) == 0) { if (plx->al_value == NULL) { - snprintf(hook_msg, HOOK_MSG_SIZE, - "input-file is NULL"); + pbs_asprintf(&hook_msg, "input-file is NULL"); goto mgr_hook_import_error; } if (is_full_path(plx->al_value)) { - snprintf(hook_msg, HOOK_MSG_SIZE, - "<%s> path must be relative to %s", + pbs_asprintf(&hook_msg, "<%s> path must be relative to %s", INPUT_FILE_PARAM, path_hooks_workdir); goto mgr_hook_import_error; } strcpy(input_file, plx->al_value); } else { - snprintf(hook_msg, HOOK_MSG_SIZE, - "unrecognized parameter - %s", + pbs_asprintf(&hook_msg, "unrecognized parameter - %s", plx->al_name); goto mgr_hook_import_error; } @@ -1259,11 +1251,12 @@ mgr_hook_import(struct batch_request *preq) char *p; FILE *temp_fp; char *p2; - char tempfile_path[MAXPATHLEN+1]; + char tempfile_path[MAXPATHLEN + 1]; + p = strrchr(input_file, '.'); if (p != NULL) { if (!in_string_list(p, ' ', VALID_HOOK_CONFIG_SUFFIX)) { - snprintf(hook_msg, HOOK_MSG_SIZE, + pbs_asprintf(&hook_msg, "<%s> contains an invalid suffix, " "should be one of: %s", INPUT_FILE_PARAM, @@ -1272,18 +1265,19 @@ mgr_hook_import(struct batch_request *preq) } if (strcmp(p, ".py") == 0) { - snprintf(input_file_path, MAXPATHLEN, + snprintf(input_file_path, sizeof(input_file_path), "%s%s", path_hooks_workdir, input_file); - rc = py_compile_and_run(input_file_path, hook_msg, - sizeof(hook_msg)-1, hookname, 1); + rc = py_compile_and_run(input_file_path, msgbuf, + sizeof(msgbuf) - 1, hookname, 1); if (rc != 0) { + hook_msg = strdup(msgbuf); goto mgr_hook_import_error; } } else if (strcmp(p, ".ini") == 0) { - snprintf(input_file_path, MAXPATHLEN, + snprintf(input_file_path, sizeof(input_file_path), "%s%s", path_hooks_workdir, input_file); - strncpy(tempfile_path, input_file_path, - MAXPATHLEN-1); + snprintf(tempfile_path, sizeof(tempfile_path), + "%s", input_file_path); p2 = strrchr(tempfile_path, '.'); *p2 = '\0'; temp_fp = fopen(tempfile_path, "w"); @@ -1295,17 +1289,18 @@ mgr_hook_import(struct batch_request *preq) "Config.read(\"%s\")\n", input_file_path); fclose(temp_fp); rc = py_compile_and_run(tempfile_path, - hook_msg, sizeof(hook_msg)-1, + msgbuf, sizeof(msgbuf) - 1, hookname, 0); if (rc != 0) { + hook_msg = strdup(msgbuf); goto mgr_hook_import_error; } } } else if (strcmp(p, ".json") == 0) { - snprintf(input_file_path, MAXPATHLEN, + snprintf(input_file_path, sizeof(input_file_path), "%s%s", path_hooks_workdir, input_file); - strncpy(tempfile_path, input_file_path, - MAXPATHLEN-1); + snprintf(tempfile_path, sizeof(tempfile_path), + "%s", input_file_path); p2 = strrchr(tempfile_path, '.'); *p2 = '\0'; temp_fp = fopen(tempfile_path, "w"); @@ -1321,9 +1316,10 @@ mgr_hook_import(struct batch_request *preq) "fd.close()\n"); fclose(temp_fp); rc = py_compile_and_run(tempfile_path, - hook_msg, sizeof(hook_msg)-1, + msgbuf, sizeof(msgbuf) - 1, hookname, 0); if (rc != 0) { + hook_msg = strdup(msgbuf); goto mgr_hook_import_error; } } @@ -1331,22 +1327,21 @@ mgr_hook_import(struct batch_request *preq) } } - snprintf(input_path, MAXPATHLEN, + snprintf(input_path, sizeof(input_path), "%s%s", path_hooks_workdir, input_file); - snprintf(temp_path, MAXPATHLEN, - "%s%s.tmp", path_hooks_workdir, input_file); + snprintf(temp_path, sizeof(temp_path), "%s%.*s.tmp", path_hooks_workdir, + (int)(sizeof(temp_path) - strlen(input_file) - 5), input_file); if (strcmp(content_type, HOOKSTR_CONTENT) == 0) { - snprintf(output_path, MAXPATHLEN, + snprintf(output_path, sizeof(output_path), "%s%s%s", path_hooks, hookname, HOOK_SCRIPT_SUFFIX); } else if (strcmp(content_type, HOOKSTR_CONFIG) == 0) { - snprintf(output_path, MAXPATHLEN, + snprintf(output_path, sizeof(output_path), "%s%s%s", path_hooks, hookname, HOOK_CONFIG_SUFFIX); } else { - snprintf(hook_msg, HOOK_MSG_SIZE-1, - "<%s> is unknown", CONTENT_TYPE_PARAM); + pbs_asprintf(&hook_msg, "<%s> is unknown", CONTENT_TYPE_PARAM); goto mgr_hook_import_error; } @@ -1356,14 +1351,17 @@ mgr_hook_import(struct batch_request *preq) if (strcmp(content_type, HOOKSTR_CONFIG) == 0) { if (decode_hook_content(input_path, output_path, content_encoding, - hook_msg, sizeof(hook_msg)) != 0) + msgbuf, sizeof(msgbuf)) != 0) { + hook_msg = strdup(msgbuf); goto mgr_hook_import_error; + } if (overwrite) { - snprintf(hook_msg, HOOK_MSG_SIZE, + pbs_asprintf(&hook_msg, "hook '%s' contents overwritten", hookname); log_event(PBSEVENT_DEBUG2, PBS_EVENTCLASS_HOOK, LOG_INFO, __func__, hook_msg); reply_text(preq, 0, hook_msg); + free(hook_msg); } else { reply_ack(preq); } @@ -1377,14 +1375,16 @@ mgr_hook_import(struct batch_request *preq) } else { if (decode_hook_content(input_path, temp_path, content_encoding, - hook_msg, sizeof(hook_msg)) != 0) + msgbuf, sizeof(msgbuf)) != 0) { + hook_msg = strdup(msgbuf); goto mgr_hook_import_error; + } } /* create a py_script */ if (pbs_python_ext_alloc_python_script(temp_path, (struct python_script **) &py_test_script) == -1) { - snprintf(hook_msg, HOOK_MSG_SIZE, + pbs_asprintf(&hook_msg, "failed to allocate storage for python script %s", temp_path); unlink(temp_path); @@ -1399,13 +1399,12 @@ mgr_hook_import(struct batch_request *preq) if (rc != 0) { if (overwrite) - snprintf(hook_msg, sizeof(hook_msg), + pbs_asprintf(&hook_msg, "Failed to compile script, " "hook '%s' contents not overwritten", hookname); else - snprintf(hook_msg, sizeof(hook_msg), - "Failed to compile script"); + pbs_asprintf(&hook_msg, "Failed to compile script"); unlink(temp_path); goto mgr_hook_import_error; @@ -1413,7 +1412,8 @@ mgr_hook_import(struct batch_request *preq) /* now actually overwrite the old file, no decoding this time */ if (decode_hook_content(temp_path, output_path, HOOKSTR_DEFAULT, - hook_msg, sizeof(hook_msg)) != 0) { + msgbuf, sizeof(msgbuf)) != 0) { + hook_msg = strdup(msgbuf); unlink(temp_path); goto mgr_hook_import_error; } @@ -1421,13 +1421,12 @@ mgr_hook_import(struct batch_request *preq) unlink(temp_path); if (overwrite) { - snprintf(hook_msg, HOOK_MSG_SIZE, - "hook '%s' contents overwritten", hookname); + pbs_asprintf(&hook_msg, "hook '%s' contents overwritten", hookname); log_event(PBSEVENT_DEBUG2, PBS_EVENTCLASS_HOOK, LOG_INFO, __func__, hook_msg); reply_text(preq, 0, hook_msg); + free(hook_msg); } else { - reply_ack(preq); } @@ -1439,7 +1438,7 @@ mgr_hook_import(struct batch_request *preq) if (pbs_python_ext_alloc_python_script(output_path, (struct python_script **)&phook->script) == -1) { - snprintf(hook_msg, HOOK_MSG_SIZE, + pbs_asprintf(&hook_msg, "failed to allocate storage for python script %s", output_path); goto mgr_hook_import_error; @@ -1469,6 +1468,7 @@ mgr_hook_import(struct batch_request *preq) unlink(temp_path); reply_text(preq, PBSE_HOOKERROR, hook_msg); log_event(PBSEVENT_DEBUG, PBS_EVENTCLASS_HOOK, LOG_INFO, __func__, hook_msg); + free(hook_msg); } @@ -1487,14 +1487,14 @@ void mgr_hook_export(struct batch_request *preq) { svrattrl *plist, *plx; - char hookname[PBS_MAXSVRJOBID + 1] = {0}; + char hookname[PBS_MAXSVRJOBID + 1] = {'\0'}; hook *phook; char content_type[BUFSIZ]; char content_encoding[BUFSIZ]; char output_file[MAXPATHLEN + 1]; - char input_path[MAXPATHLEN + 1] = {0}; - char output_path[MAXPATHLEN + 1] = {0}; - char hook_msg[HOOK_MSG_SIZE] = {0}; + char input_path[MAXPATHLEN + 1] = {'\0'}; + char output_path[MAXPATHLEN + 1] = {'\0'}; + char hook_msg[HOOK_MSG_SIZE] = {'\0'}; int hook_obj; hook_obj = preq->rq_ind.rq_manager.rq_objtype; @@ -1504,13 +1504,14 @@ mgr_hook_export(struct batch_request *preq) return; } - strncpy(hookname, preq->rq_ind.rq_manager.rq_objname, PBS_MAXSVRJOBID); + snprintf(hookname, sizeof(hookname), "%.*s", PBS_MAXSVRJOBID, + preq->rq_ind.rq_manager.rq_objname); /* Else one and only one vhook */ phook = find_hook(hookname); if ((phook == NULL) || phook->pending_delete) { - snprintf(hook_msg, HOOK_MSG_SIZE, "%s does not exist!", hookname); + snprintf(hook_msg, sizeof(hook_msg), "%s does not exist!", hookname); log_event(PBSEVENT_ADMIN, PBS_EVENTCLASS_HOOK, LOG_INFO, hookname, hook_msg); reply_text(preq, PBSE_HOOKERROR, hook_msg); return; @@ -1520,7 +1521,7 @@ mgr_hook_export(struct batch_request *preq) /* But HOOK_PBS hooks can also be shown if the qmgr request is */ /* specifically operating on the "pbshook" keyword. */ if ((phook->type != HOOK_SITE) && (hook_obj != MGR_OBJ_PBS_HOOK)) { - snprintf(hook_msg, HOOK_MSG_SIZE, "%s not of '%s' type", hookname, HOOKSTR_SITE); + snprintf(hook_msg, sizeof(hook_msg), "%s not of '%s' type", hookname, HOOKSTR_SITE); log_event(PBSEVENT_ADMIN, PBS_EVENTCLASS_HOOK, LOG_INFO, hookname, hook_msg); reply_text(preq, PBSE_HOOKERROR, hook_msg); return; @@ -1529,7 +1530,7 @@ mgr_hook_export(struct batch_request *preq) /* Cannot show a HOOK_SITE hook if the qmgr request keyword is */ /* "pbshook" */ if ((phook->type == HOOK_SITE) && (hook_obj == MGR_OBJ_PBS_HOOK)) { - snprintf(hook_msg, HOOK_MSG_SIZE, "%s not of '%s' type", hookname, HOOKSTR_PBS); + snprintf(hook_msg, sizeof(hook_msg), "%s not of '%s' type", hookname, HOOKSTR_PBS); log_event(PBSEVENT_ADMIN, PBS_EVENTCLASS_HOOK, LOG_INFO, hookname, hook_msg); reply_text(preq, PBSE_HOOKERROR, hook_msg); return; @@ -1548,13 +1549,13 @@ mgr_hook_export(struct batch_request *preq) if (strcasecmp(plx->al_name, CONTENT_TYPE_PARAM) == 0) { if (plx->al_value == NULL) { - snprintf(hook_msg, HOOK_MSG_SIZE, + snprintf(hook_msg, sizeof(hook_msg), "<%s> is NULL", CONTENT_TYPE_PARAM); goto mgr_hook_export_error; } if (hook_obj == MGR_OBJ_PBS_HOOK) { if (strcmp(plx->al_value, HOOKSTR_CONFIG) != 0) { - snprintf(hook_msg, HOOK_MSG_SIZE, + snprintf(hook_msg, sizeof(hook_msg), "<%s> must be %s", CONTENT_TYPE_PARAM, HOOKSTR_CONFIG); goto mgr_hook_export_error; @@ -1562,7 +1563,7 @@ mgr_hook_export(struct batch_request *preq) } else if ((strcmp(plx->al_value, HOOKSTR_CONTENT) != 0) && (strcmp(plx->al_value, HOOKSTR_CONFIG) != 0)) { - snprintf(hook_msg, HOOK_MSG_SIZE, + snprintf(hook_msg, sizeof(hook_msg), "<%s> must be %s", CONTENT_TYPE_PARAM, HOOKSTR_CONTENT); goto mgr_hook_export_error; @@ -1571,13 +1572,13 @@ mgr_hook_export(struct batch_request *preq) } else if (strcasecmp(plx->al_name, CONTENT_ENCODING_PARAM) == 0) { if (plx->al_value == NULL) { - snprintf(hook_msg, HOOK_MSG_SIZE, + snprintf(hook_msg, sizeof(hook_msg), "<%s> is NULL", CONTENT_ENCODING_PARAM); goto mgr_hook_export_error; } if ((strcmp(plx->al_value, HOOKSTR_DEFAULT) != 0) && (strcmp(plx->al_value, HOOKSTR_BASE64) != 0)) { - snprintf(hook_msg, HOOK_MSG_SIZE, + snprintf(hook_msg, sizeof(hook_msg), "<%s> must be '%s' or '%s'", CONTENT_ENCODING_PARAM, HOOKSTR_DEFAULT, HOOKSTR_BASE64); @@ -1586,20 +1587,20 @@ mgr_hook_export(struct batch_request *preq) strcpy(content_encoding, plx->al_value); } else if (strcasecmp(plx->al_name, OUTPUT_FILE_PARAM) == 0) { if (plx->al_value == NULL) { - snprintf(hook_msg, HOOK_MSG_SIZE, + snprintf(hook_msg, sizeof(hook_msg), "<%s> is NULL", OUTPUT_FILE_PARAM); goto mgr_hook_export_error; } if (is_full_path(plx->al_value)) { - snprintf(hook_msg, HOOK_MSG_SIZE, + snprintf(hook_msg, sizeof(hook_msg), "<%s> path must be relative to %s", OUTPUT_FILE_PARAM, path_hooks_workdir); goto mgr_hook_export_error; } strcpy(output_file, plx->al_value); } else { - snprintf(hook_msg, HOOK_MSG_SIZE, + snprintf(hook_msg, sizeof(hook_msg), "unrecognized parameter - %s", plx->al_name); goto mgr_hook_export_error; @@ -1616,13 +1617,13 @@ mgr_hook_export(struct batch_request *preq) snprintf(input_path, MAXPATHLEN, "%s%s%s", path_hooks, hookname, HOOK_CONFIG_SUFFIX); } else { - snprintf(hook_msg, HOOK_MSG_SIZE, + snprintf(hook_msg, sizeof(hook_msg), "<%s> is unknown", CONTENT_TYPE_PARAM); goto mgr_hook_export_error; } - snprintf(output_path, MAXPATHLEN, "%s%s", path_hooks_workdir, - output_file); + snprintf(output_path, sizeof(output_path), "%s%.*s", path_hooks_workdir, + (int)(sizeof(output_path) - strlen(output_file)), output_file); if (encode_hook_content(input_path, output_path, content_encoding, hook_msg, sizeof(hook_msg)) != 0) goto mgr_hook_export_error; @@ -1713,7 +1714,7 @@ copy_hook(hook *src_hook, hook *dst_hook, int mode) * returns a reply to the sender of the batch_request * @note * This is an atomic operation - either all the listed attributes - * are set or none at all - uses copy_hook() to save/restore values. + * are set or none at all - uses copy_hook() to save/restore values. * * @see * req_manager @@ -1725,11 +1726,11 @@ mgr_hook_set(struct batch_request *preq) { svrattrl *plist, *plx; - char hookname[PBS_MAXSVRJOBID + 1] = {0}; + char hookname[PBS_MAXSVRJOBID + 1] = {'\0'}; hook *phook; int num_set = 0; int got_event = 0; /* event attribute operated on */ - char hook_msg[HOOK_MSG_SIZE] = {0}; + char hook_msg[HOOK_MSG_SIZE] = {'\0'}; hook shook; unsigned int prev_phook_event = 0; char *hook_user_val = NULL; @@ -1745,12 +1746,12 @@ mgr_hook_set(struct batch_request *preq) return; } - strncpy(hookname, preq->rq_ind.rq_manager.rq_objname, PBS_MAXSVRJOBID); + snprintf(hookname, sizeof(hookname), "%s", preq->rq_ind.rq_manager.rq_objname); phook = find_hook(hookname); if ((phook == NULL) || phook->pending_delete) { - snprintf(hook_msg, HOOK_MSG_SIZE, "%s does not exist!", hookname); + snprintf(hook_msg, sizeof(hook_msg), "%s does not exist!", hookname); log_event(PBSEVENT_ADMIN, PBS_EVENTCLASS_HOOK, LOG_INFO, hookname, hook_msg); reply_text(preq, PBSE_HOOKERROR, hook_msg); return; @@ -1813,8 +1814,8 @@ mgr_hook_set(struct batch_request *preq) else { sprintf(log_buffer, "periodic hook is missing information, check hook frequency and script"); log_event(PBSEVENT_ADMIN, PBS_EVENTCLASS_HOOK, LOG_INFO, - hookname, log_buffer); - snprintf(hook_msg, HOOK_MSG_SIZE, + hookname, log_buffer); + snprintf(hook_msg, sizeof(hook_msg), "periodic hook is missing information, check hook frequency and script"); goto mgr_hook_set_error; } @@ -1844,7 +1845,7 @@ mgr_hook_set(struct batch_request *preq) free(hook_user_val); hook_user_val = strdup(plx->al_value); if (hook_user_val == NULL) { - snprintf(hook_msg, HOOK_MSG_SIZE, + snprintf(hook_msg, sizeof(hook_msg), "strdup(%s) failed: errno %d", plx->al_value, errno); goto mgr_hook_set_error; @@ -1858,7 +1859,7 @@ mgr_hook_set(struct batch_request *preq) free(hook_fail_action_val); hook_fail_action_val = strdup(plx->al_value); if (hook_fail_action_val == NULL) { - snprintf(hook_msg, HOOK_MSG_SIZE, + snprintf(hook_msg, sizeof(hook_msg), "strdup(%s) failed: errno %d", plx->al_value, errno); goto mgr_hook_set_error; @@ -1921,7 +1922,7 @@ mgr_hook_set(struct batch_request *preq) num_set++; break; default: - snprintf(hook_msg, HOOK_MSG_SIZE, + snprintf(hook_msg, sizeof(hook_msg), "%s - %s:%d", msg_internal, plx->al_name, plx->al_op); goto mgr_hook_set_error; @@ -1933,7 +1934,7 @@ mgr_hook_set(struct batch_request *preq) if (phook->event & HOOK_EVENT_PERIODIC) { sprintf(log_buffer, "Setting order for a periodic hook has no effect"); log_event(PBSEVENT_ADMIN, PBS_EVENTCLASS_HOOK, LOG_INFO, - hookname, log_buffer); + hookname, log_buffer); } else if (set_hook_order(phook, plx->al_value, hook_msg, sizeof(hook_msg)) != 0) goto mgr_hook_set_error; @@ -1956,7 +1957,7 @@ mgr_hook_set(struct batch_request *preq) free(hook_freq_val); hook_freq_val = strdup(plx->al_value); if (hook_freq_val == NULL) { - snprintf(hook_msg, HOOK_MSG_SIZE, + snprintf(hook_msg, sizeof(hook_msg), "strdup(%s) failed: errno %d", plx->al_value, errno); goto mgr_hook_set_error; @@ -2008,7 +2009,7 @@ mgr_hook_set(struct batch_request *preq) num_set++; break; default: - snprintf(hook_msg, HOOK_MSG_SIZE, + snprintf(hook_msg, sizeof(hook_msg), "%s - %s:%d", msg_internal, plx->al_name, plx->al_op); goto mgr_hook_set_error; @@ -2028,7 +2029,7 @@ mgr_hook_set(struct batch_request *preq) if (num_set > 0) { if (hook_save(phook) != 0) { - snprintf(hook_msg, HOOK_MSG_SIZE, + snprintf(hook_msg, sizeof(hook_msg), "Failed to store '%s' permanently.", preq->rq_ind.rq_manager.rq_objname); goto mgr_hook_set_error; @@ -2078,7 +2079,7 @@ mgr_hook_set(struct batch_request *preq) return; opnotequal: - snprintf(hook_msg, HOOK_MSG_SIZE, "'%s' operator not =", + snprintf(hook_msg, sizeof(hook_msg), "'%s' operator not =", plx->al_name); mgr_hook_set_error: @@ -2090,9 +2091,11 @@ mgr_hook_set(struct batch_request *preq) free(hook_freq_val); if ((num_set > 0) || got_event) { - /* got_event of 1 means set_hook_event() was called which */ - /* would have automatically initialized phook->event to 0; */ - /* so we'll need to restore previous value */ + /* + * got_event of 1 means set_hook_event() was called which + * would have automatically initialized phook->event to 0 + * so we'll need to restore previous value + */ copy_hook(&shook, phook, COPY_HOOK_RESTORE); } @@ -2112,7 +2115,7 @@ mgr_hook_set(struct batch_request *preq) * * @note * This is an atomic operation - either all the listed attributes - * are unset or none at all - uses copy_hook() to save/restore + * are unset or none at all - uses copy_hook() to save/restore * values. * * @param[in] preq - batch_request structure representing the request. @@ -2123,10 +2126,10 @@ mgr_hook_unset(struct batch_request *preq) { svrattrl *plist, *plx; - char hookname[PBS_MAXSVRJOBID + 1] = {0}; + char hookname[PBS_MAXSVRJOBID + 1] = {'\0'}; hook *phook; int num_unset = 0; - char hook_msg[HOOK_MSG_SIZE] = {0}; + char hook_msg[HOOK_MSG_SIZE] = {'\0'}; hook shook; unsigned int prev_phook_event; int hook_obj; @@ -2138,13 +2141,13 @@ mgr_hook_unset(struct batch_request *preq) return; } - strncpy(hookname, preq->rq_ind.rq_manager.rq_objname, PBS_MAXSVRJOBID); + snprintf(hookname, sizeof(hookname), "%s", preq->rq_ind.rq_manager.rq_objname); /* Else one and only one vhook */ phook = find_hook(hookname); if ((phook == NULL) || phook->pending_delete) { - snprintf(hook_msg, HOOK_MSG_SIZE, "%s does not exist!", hookname); + snprintf(hook_msg, sizeof(hook_msg), "%s does not exist!", hookname); log_event(PBSEVENT_ADMIN, PBS_EVENTCLASS_HOOK, LOG_INFO, hookname, hook_msg); reply_text(preq, PBSE_HOOKERROR, hook_msg); return; @@ -2242,7 +2245,7 @@ mgr_hook_unset(struct batch_request *preq) if (num_unset > 0) { if (hook_save(phook) != 0) { - snprintf(hook_msg, HOOK_MSG_SIZE, + snprintf(hook_msg, sizeof(hook_msg), "Failed to store '%s' permanently.", preq->rq_ind.rq_manager.rq_objname); goto mgr_hook_unset_error; @@ -2300,7 +2303,7 @@ mgr_hook_unset(struct batch_request *preq) * @param[out] msg_len - required length of output message * * @return Error code - * @retval 0 - Success + * @retval 0 - Success * @retval nonzero - Failure */ @@ -2706,8 +2709,7 @@ set_hold_types(job *pjob, char *new_hold_types_str, char buf[HOOK_BUF_SIZE]; /* Note the hold time in the job comment. */ now = time(NULL); - (void)strncpy(date, (const char *)ctime(&now), 32); - date[strlen(date)-1] = '\0'; + snprintf(date, sizeof(date), "%s", (const char *)ctime(&now)); (void)sprintf(buf, "Job held by '%s' hook on %s", hook_name, date); job_attr_def[(int)JOB_ATR_Comment].at_decode( @@ -2780,8 +2782,9 @@ set_attribute(job *pjob, int attr_index, return (2); } - /* Need to dup 'new_str' for if fed to job attribute's decode function, - cannot guarantee that the value will not get "munged". + /* + * Need to dup 'new_str' for if fed to job attribute's decode function, + * cannot guarantee that the value will not get "munged". */ new_attrval_str = strdup(new_str); if (new_attrval_str == NULL) { @@ -2933,9 +2936,10 @@ set_job_varlist(job *pjob, char *hook_name, char *msg, int msg_len) if (elen > 0) { orig_env_str = (char *)malloc(elen); if (orig_env_str == NULL) { - snprintf(msg, msg_len-1, - "malloc failure setting job's Variable_List"); - log_err(errno, pjob->ji_qs.ji_jobid, msg); + snprintf(msg, msg_len - 1, + "malloc failure setting Variable_List for job %s", + pjob->ji_qs.ji_jobid); + log_err(errno, __func__, msg); return (1); } memset(orig_env_str, '\0', elen); @@ -3244,7 +3248,7 @@ attribute_jobmap_clear(struct attribute_jobmap *a_map) /** * @brief - * Restores pjob's attribute values saved in 'a_map'. + * Restores pjob's attribute values saved in 'a_map'. * * @see * process_hooks @@ -3611,9 +3615,7 @@ write_hook_reject_debug_output_and_close(char *reject_msg) snprintf(log_buffer, sizeof(log_buffer), "warning: open of hook debug output file %s failed!", hook_outfile); - log_err(-1, - "write_hook_reject_output_and_close", - log_buffer); + log_err(-1, __func__, log_buffer); } else { pbs_python_set_hook_debug_output_fp(fp_debug_out); } @@ -3664,9 +3666,7 @@ write_hook_accept_debug_output_and_close(void) snprintf(log_buffer, sizeof(log_buffer), "warning: open of hook debug output file %s failed!", hook_outfile); - log_err(-1, - "write_hook_accept_output_and_close", - log_buffer); + log_err(-1, __func__, log_buffer); } else { pbs_python_set_hook_debug_output_fp(fp_debug_out); } @@ -3711,15 +3711,18 @@ get_vnode_list(void){ strcat(name_str_buf, "."); strncat(name_str_buf, (padef+index)->at_name, (STRBUF - strlen(name_str_buf))); if ((padef+index)->at_encode( - &pnode->nd_attr[index], - &vnode_attr_list, name_str_buf, - (char *)0, ATR_ENCODE_HOOK, NULL) < 0) { - snprintf(log_buffer, sizeof(log_buffer), + &pnode->nd_attr[index], + &vnode_attr_list, name_str_buf, + NULL, ATR_ENCODE_HOOK, NULL) < 0) { + char *msgbuf; + + pbs_asprintf(&msgbuf, "error on encoding node attributes: %s", name_str_buf); log_event(PBSEVENT_DEBUG2, PBS_EVENTCLASS_HOOK, LOG_ERR, - __func__, log_buffer); + __func__, msgbuf); + free(msgbuf); break; } } @@ -3747,22 +3750,25 @@ get_resv_list(void) { CLEAR_HEAD(resv_attr_list); presv = (resc_resv *)GET_NEXT(svr_allresvs); - while (presv != (resc_resv *)0) { + while (presv != NULL) { for (index = 0; index < RESV_ATR_LAST; index++) { if ((padef+index)->at_flags & ATR_VFLAG_SET) { strncpy(name_str_buf, presv->ri_qs.ri_resvID, STRBUF); strcat(name_str_buf, "."); strncat(name_str_buf, (padef+index)->at_name, (STRBUF - strlen(name_str_buf))); if ((padef+index)->at_encode( - &presv->ri_wattr[index], - &resv_attr_list, name_str_buf, - (char *)0, ATR_ENCODE_HOOK, NULL) < 0) { - snprintf(log_buffer, sizeof(log_buffer), + &presv->ri_wattr[index], + &resv_attr_list, name_str_buf, + NULL, ATR_ENCODE_HOOK, NULL) < 0) { + char *msgbuf; + + pbs_asprintf(&msgbuf, "error on encoding reservation attributes: %s", name_str_buf); log_event(PBSEVENT_DEBUG2, PBS_EVENTCLASS_HOOK, LOG_ERR, - __func__, log_buffer); + __func__, msgbuf); + free(msgbuf); break; } } @@ -3921,8 +3927,8 @@ process_hooks(struct batch_request *preq, char *hook_msg, size_t msg_len, continue; } rc = server_process_hooks(preq->rq_type, preq->rq_user, preq->rq_host, phook, - hook_event, pjob, &req_ptr, hook_msg, msg_len, pyinter_func, - &num_run, &event_initialized); + hook_event, pjob, &req_ptr, hook_msg, msg_len, pyinter_func, + &num_run, &event_initialized); if ((rc == 0) || (rc == -1)) return (rc); } @@ -4144,9 +4150,11 @@ int server_process_hooks(int rq_type, char *rq_user, char *rq_host, hook *phook, return (-1); } - /* hook_type needed for internal processing; */ - /* hook_type changes for each hook. */ - /* This sets Python event object's hook_type value */ + /* + * hook_type needed for internal processing; + * hook_type changes for each hook. + * This sets Python event object's hook_type value + */ rc = pbs_python_event_set_attrval(PY_EVENT_HOOK_TYPE, hook_type_as_string(phook->type)); @@ -4343,12 +4351,15 @@ int server_process_hooks(int rq_type, char *rq_user, char *rq_host, hook *phook, fp_debug_out = fopen(hook_outfile, "w"); if (fp_debug_out == NULL) { - sprintf(log_buffer, + char *msgbuf; + + pbs_asprintf(&msgbuf, "warning: open of debug output file %s failed!", hook_inputfile); log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_HOOK, LOG_ERR, - phook->hook_name, log_buffer); + phook->hook_name, msgbuf); + free(msgbuf); if (rq_type == PBS_BATCH_HookPeriodic) /* we will need output file to read data from hook later */ return (-1); @@ -4858,8 +4869,7 @@ add_mom_hook_action(mom_hook_action_t ***hookact_array, pact = (mom_hook_action_t *)malloc(sizeof(mom_hook_action_t)); if (pact != NULL) { - (void)strncpy(pact->hookname, hookname, MAXPATHLEN); - pact->hookname[MAXPATHLEN] = '\0'; + snprintf(pact->hookname, sizeof(pact->hookname), "%s", hookname); pact->action = action; pact->do_delete_action_first = 0; pact->tid = input_tid; @@ -4991,7 +5001,7 @@ find_mom_hook_action(mom_hook_action_t **hookact_array, * For every successful pending action add, a line of data is * written in [PATH_HOOKS]/hook_tracking.TR file as: * : - * where is the current action flag value. + * where is the current action flag value. * * @param[in] minfo - if not NULL, then add mom hook action * on this particular mom in 'minfo'. @@ -5307,9 +5317,11 @@ sync_mom_hookfiles(void *minfo) continue; momport =minfo_array[i]->mi_port; - pbs_errno=0; - for (j=0; j < minfo_array[i]->mi_num_action; j++) { + pbs_errno = 0; + for (j = 0; j < minfo_array[i]->mi_num_action; j++) { + char *msgbuf; hook *phook; + pact = minfo_array[i]->mi_action[j]; if ((pact == NULL) || (pact->action == MOM_HOOK_ACTION_NONE)) @@ -5387,24 +5399,24 @@ sync_mom_hookfiles(void *minfo) /* have a suffix */ if (pact->action & MOM_HOOK_ACTION_DELETE_RESCDEF) { - strncpy(hookfile, pact->hookname, MAXPATHLEN-1); + snprintf(hookfile, sizeof(hookfile), "%s", pact->hookname); if (PBSD_delhookfile(conn, hookfile, 0, NULL) != 0) { - snprintf(log_buffer, sizeof(log_buffer), + pbs_asprintf(&msgbuf, "errno %d: failed to delete rescdef file %s from %s", pbs_errno, hookfile, minfo_array[i]->mi_host); log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_WARNING, - msg_daemonname, log_buffer); + msg_daemonname, msgbuf); + free(msgbuf); } else { - - snprintf(log_buffer, sizeof(log_buffer), + pbs_asprintf(&msgbuf, "successfully deleted rescdef file %s from %s:%d", - hookfile, minfo_array[i]->mi_host, - minfo_array[i]->mi_port); + hookfile, minfo_array[i]->mi_host, minfo_array[i]->mi_port); log_event(PBSEVENT_DEBUG, PBS_EVENTCLASS_REQUEST, LOG_INFO, - msg_daemonname, log_buffer); + msg_daemonname, msgbuf); + free(msgbuf); /* Delete all SEND_RESCDEF action */ /* so it doesn't get retried for this */ /* "deleted" resourcdef. */ @@ -5415,28 +5427,27 @@ sync_mom_hookfiles(void *minfo) } else if (pact->action & MOM_HOOK_ACTION_SEND_RESCDEF) { - snprintf(hookfile, MAXPATHLEN, "%s%s", - path_hooks, pact->hookname); + snprintf(hookfile, sizeof(hookfile), "%s%.*s", path_hooks, + (int)(sizeof(hookfile) - strlen(path_hooks)), pact->hookname); if ((PBSD_copyhookfile(conn, hookfile, 0, NULL) != 0) && (pbs_errno != PBSE_MOM_REJECT_ROOT_SCRIPTS)) { - snprintf(log_buffer, sizeof(log_buffer), + pbs_asprintf(&msgbuf, "errno %d: failed to copy rescdef file %s to %s:%d", - pbs_errno, hookfile, - minfo_array[i]->mi_host, - minfo_array[i]->mi_port); + pbs_errno, hookfile, minfo_array[i]->mi_host, minfo_array[i]->mi_port); log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_WARNING, - msg_daemonname, log_buffer); + msg_daemonname, msgbuf); + free(msgbuf); } else { if (pbs_errno != PBSE_MOM_REJECT_ROOT_SCRIPTS) { - snprintf(log_buffer, sizeof(log_buffer), + pbs_asprintf(&msgbuf, "successfully sent rescdef file %s to %s:%d", - hookfile, minfo_array[i]->mi_host, - minfo_array[i]->mi_port); + hookfile, minfo_array[i]->mi_host, minfo_array[i]->mi_port); log_event(PBSEVENT_DEBUG, PBS_EVENTCLASS_REQUEST, LOG_INFO, - msg_daemonname, log_buffer); + msg_daemonname, msgbuf); + free(msgbuf); } else { snprintf(log_buffer, sizeof(log_buffer), "warning: sending resourcedef to %s:%d got rejected (mom's reject_root_scripts=1)", @@ -5455,25 +5466,26 @@ sync_mom_hookfiles(void *minfo) /* execute delete action before the send actions */ if (pact->do_delete_action_first && (pact->action & MOM_HOOK_ACTION_DELETE)) { /* delete a hook - overrides other hook actions */ - snprintf(hookfile, MAXPATHLEN, "%s%s", + snprintf(hookfile, sizeof(hookfile), "%.*s%s", + (int)(sizeof(hookfile) - strlen(HOOK_FILE_SUFFIX) - 1), pact->hookname, HOOK_FILE_SUFFIX); if (PBSD_delhookfile(conn, hookfile, 0, NULL) != 0) { - snprintf(log_buffer, sizeof(log_buffer), + pbs_asprintf(&msgbuf, "errno %d: failed to delete hook file %s from %s", pbs_errno, hookfile, minfo_array[i]->mi_host); log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_WARNING, - msg_daemonname, log_buffer); + msg_daemonname, msgbuf); + free(msgbuf); } else { - - snprintf(log_buffer, sizeof(log_buffer), + pbs_asprintf(&msgbuf, "successfully deleted hook file %s from %s:%d", - hookfile, minfo_array[i]->mi_host, - minfo_array[i]->mi_port); + hookfile, minfo_array[i]->mi_host, minfo_array[i]->mi_port); log_event(PBSEVENT_DEBUG, PBS_EVENTCLASS_REQUEST, LOG_INFO, - msg_daemonname, log_buffer); + msg_daemonname, msgbuf); + free(msgbuf); /* Delete also any other hook-related actions */ /* so they don't get erroneously retried */ @@ -5493,37 +5505,37 @@ sync_mom_hookfiles(void *minfo) */ if (pact->action & MOM_HOOK_ACTION_SEND_ATTRS) { - snprintf(hookfile, MAXPATHLEN, "%s%s%s", - path_hooks, pact->hookname, HOOK_FILE_SUFFIX); + snprintf(hookfile, sizeof(hookfile), "%.*s%.*s%s", + (int)(sizeof(hookfile) - PBS_HOOK_NAME_SIZE - strlen(HOOK_FILE_SUFFIX)), + path_hooks, PBS_HOOK_NAME_SIZE, pact->hookname, HOOK_FILE_SUFFIX); if (!phook || (phook->event & MOM_EVENTS) == 0) { pact->action &= ~MOM_HOOK_ACTION_SEND_ATTRS; } else if ((PBSD_copyhookfile(conn, hookfile, 0, NULL) != 0) && (pbs_errno != PBSE_MOM_REJECT_ROOT_SCRIPTS)) { - snprintf(log_buffer, sizeof(log_buffer), + pbs_asprintf(&msgbuf, "errno %d: failed to copy hook file %s to %s:%d", - pbs_errno, hookfile, - minfo_array[i]->mi_host, - minfo_array[i]->mi_port); + pbs_errno, hookfile, minfo_array[i]->mi_host, minfo_array[i]->mi_port); log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_WARNING, - msg_daemonname, log_buffer); + msg_daemonname, msgbuf); + free(msgbuf); } else { if (pbs_errno != PBSE_MOM_REJECT_ROOT_SCRIPTS) { - snprintf(log_buffer, sizeof(log_buffer), + pbs_asprintf(&msgbuf, "successfully sent hook file %s to %s:%d", - hookfile, minfo_array[i]->mi_host, - minfo_array[i]->mi_port); + hookfile, minfo_array[i]->mi_host, minfo_array[i]->mi_port); log_event(PBSEVENT_DEBUG, PBS_EVENTCLASS_REQUEST, LOG_INFO, - msg_daemonname, log_buffer); + msg_daemonname, msgbuf); + free(msgbuf); } else { - snprintf(log_buffer, sizeof(log_buffer), + pbs_asprintf(&msgbuf, "warning: sending hook file %s to %s:%d got rejected (mom's reject_root_scripts=1)", - hookfile, minfo_array[i]->mi_host, - minfo_array[i]->mi_port); + hookfile, minfo_array[i]->mi_host, minfo_array[i]->mi_port); log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_INFO, - msg_daemonname, log_buffer); + msg_daemonname, msgbuf); + free(msgbuf); } pact->action &= ~(MOM_HOOK_ACTION_SEND_ATTRS); hook_track_save((mominfo_t *)minfo_array[i], j); @@ -5534,38 +5546,38 @@ sync_mom_hookfiles(void *minfo) /* send hook config */ if (pact->action & MOM_HOOK_ACTION_SEND_CONFIG) { - snprintf(hookfile, MAXPATHLEN, "%s%s%s", - path_hooks, pact->hookname, - HOOK_CONFIG_SUFFIX); + snprintf(hookfile, sizeof(hookfile), "%.*s%.*s%s", + (int)(sizeof(hookfile) - PBS_HOOK_NAME_SIZE - strlen(HOOK_CONFIG_SUFFIX)), + path_hooks, PBS_HOOK_NAME_SIZE, pact->hookname, HOOK_CONFIG_SUFFIX); if (!phook || (phook->event & MOM_EVENTS) == 0) { pact->action &= ~MOM_HOOK_ACTION_SEND_CONFIG; } else if ((PBSD_copyhookfile(conn, hookfile, 0, NULL) != 0) && (pbs_errno != PBSE_MOM_REJECT_ROOT_SCRIPTS)) { - snprintf(log_buffer, sizeof(log_buffer), + pbs_asprintf(&msgbuf, "errno %d: failed to copy hook file %s to %s:%d", - pbs_errno, hookfile, minfo_array[i]->mi_host, - minfo_array[i]->mi_port); + pbs_errno, hookfile, minfo_array[i]->mi_host, minfo_array[i]->mi_port); log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_WARNING, - msg_daemonname, log_buffer); + msg_daemonname, msgbuf); + free(msgbuf); } else { if (pbs_errno != PBSE_MOM_REJECT_ROOT_SCRIPTS) { - snprintf(log_buffer, sizeof(log_buffer), + pbs_asprintf(&msgbuf, "successfully sent hook file %s to %s:%d", - hookfile, minfo_array[i]->mi_host, - minfo_array[i]->mi_port); + hookfile, minfo_array[i]->mi_host, minfo_array[i]->mi_port); log_event(PBSEVENT_DEBUG, PBS_EVENTCLASS_REQUEST, LOG_INFO, - msg_daemonname, log_buffer); + msg_daemonname, msgbuf); + free(msgbuf); } else { - snprintf(log_buffer, sizeof(log_buffer), + pbs_asprintf(&msgbuf, "warning: sending hook file %s to %s:%d got rejected (mom's reject_root_scripts=1)", - hookfile, minfo_array[i]->mi_host, - minfo_array[i]->mi_port); + hookfile, minfo_array[i]->mi_host, minfo_array[i]->mi_port); log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_INFO, - msg_daemonname, log_buffer); + msg_daemonname, msgbuf); + free(msgbuf); } pact->action &= ~(MOM_HOOK_ACTION_SEND_CONFIG); hook_track_save((mominfo_t *)minfo_array[i], @@ -5577,38 +5589,38 @@ sync_mom_hookfiles(void *minfo) /* send hook content */ if (pact->action & MOM_HOOK_ACTION_SEND_SCRIPT) { - snprintf(hookfile, MAXPATHLEN, "%s%s%s", - path_hooks, pact->hookname, - HOOK_SCRIPT_SUFFIX); + snprintf(hookfile, sizeof(hookfile), "%.*s%.*s%s", + (int)(sizeof(hookfile) - PBS_HOOK_NAME_SIZE - strlen(HOOK_SCRIPT_SUFFIX)), + path_hooks, PBS_HOOK_NAME_SIZE, pact->hookname, HOOK_SCRIPT_SUFFIX); if (!phook || (phook->event & MOM_EVENTS) == 0) { pact->action &= ~MOM_HOOK_ACTION_SEND_SCRIPT; } if ((PBSD_copyhookfile(conn, hookfile, 0, NULL) != 0) && (pbs_errno != PBSE_MOM_REJECT_ROOT_SCRIPTS)) { - snprintf(log_buffer, sizeof(log_buffer), + pbs_asprintf(&msgbuf, "errno %d: failed to copy hook file %s to %s:%d", - pbs_errno, hookfile, minfo_array[i]->mi_host, - minfo_array[i]->mi_port); + pbs_errno, hookfile, minfo_array[i]->mi_host, minfo_array[i]->mi_port); log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_WARNING, - msg_daemonname, log_buffer); + msg_daemonname, msgbuf); + free(msgbuf); } else { if (pbs_errno != PBSE_MOM_REJECT_ROOT_SCRIPTS) { - snprintf(log_buffer, sizeof(log_buffer), + pbs_asprintf(&msgbuf, "successfully sent hook file %s to %s:%d", - hookfile, minfo_array[i]->mi_host, - minfo_array[i]->mi_port); + hookfile, minfo_array[i]->mi_host, minfo_array[i]->mi_port); log_event(PBSEVENT_DEBUG, PBS_EVENTCLASS_REQUEST, LOG_INFO, - msg_daemonname, log_buffer); + msg_daemonname, msgbuf); + free(msgbuf); } else { - snprintf(log_buffer, sizeof(log_buffer), + pbs_asprintf(&msgbuf, "warning: sending hook file %s to %s:%d got rejected (mom's reject_root_scripts=1)", - hookfile, minfo_array[i]->mi_host, - minfo_array[i]->mi_port); + hookfile, minfo_array[i]->mi_host, minfo_array[i]->mi_port); log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_INFO, - msg_daemonname, log_buffer); + msg_daemonname, msgbuf); + free(msgbuf); } pact->action &= ~(MOM_HOOK_ACTION_SEND_SCRIPT); hook_track_save((mominfo_t *)minfo_array[i], j); @@ -5619,25 +5631,26 @@ sync_mom_hookfiles(void *minfo) /* execute send actions above first, and then this delete action */ if (!pact->do_delete_action_first && (pact->action & MOM_HOOK_ACTION_DELETE)) { /* delete a hook - overrides other hook actions */ - snprintf(hookfile, MAXPATHLEN, "%s%s", + snprintf(hookfile, sizeof(hookfile), "%.*s%s", + (int)(sizeof(hookfile) - strlen(HOOK_FILE_SUFFIX) - 1), pact->hookname, HOOK_FILE_SUFFIX); if (PBSD_delhookfile(conn, hookfile, 0, NULL) != 0) { - snprintf(log_buffer, sizeof(log_buffer), + pbs_asprintf(&msgbuf, "errno %d: failed to delete hook file %s from %s", pbs_errno, hookfile, minfo_array[i]->mi_host); log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_WARNING, - msg_daemonname, log_buffer); + msg_daemonname, msgbuf); + free(msgbuf); } else { - - snprintf(log_buffer, sizeof(log_buffer), + pbs_asprintf(&msgbuf, "successfully deleted hook file %s from %s:%d", - hookfile, minfo_array[i]->mi_host, - minfo_array[i]->mi_port); + hookfile, minfo_array[i]->mi_host, minfo_array[i]->mi_port); log_event(PBSEVENT_DEBUG, PBS_EVENTCLASS_REQUEST, LOG_INFO, - msg_daemonname, log_buffer); + msg_daemonname, msgbuf); + free(msgbuf); /* Delete also any other hook-related actions */ /* so they don't get erroneously retried */ @@ -5740,6 +5753,7 @@ post_sendhookRPP(struct work_task *pwt) int j; int event; long long int tid; + char *msgbuf; if (!info) return; @@ -5754,7 +5768,7 @@ post_sendhookRPP(struct work_task *pwt) snprintf(log_buffer, sizeof(log_buffer), "sendhookRPP reply (tid=%lld) not from current " "batch of hook updates (tid=%lld) from mhost=%s", - tid, g_sync_hook_tid, minfo->mi_host ? minfo->mi_host : ""); + tid, g_sync_hook_tid, minfo->mi_host ? minfo->mi_host : ""); log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_SERVER, LOG_INFO, "post_sendhookRPP", log_buffer); return; /* return now as info->index no longer valid */ @@ -5763,18 +5777,21 @@ post_sendhookRPP(struct work_task *pwt) pact = minfo->mi_action[j]; if (event == MOM_HOOK_ACTION_DELETE_RESCDEF) { - snprintf(hookfile, MAXPATHLEN, "%s%s", path_hooks, pact->hookname); + snprintf(hookfile, sizeof(hookfile), "%.*s%.*s", + (int)(sizeof(hookfile) - PBS_HOOK_NAME_SIZE), + path_hooks, PBS_HOOK_NAME_SIZE, pact->hookname); if (rc != 0) { - snprintf(log_buffer, sizeof(log_buffer), - "errno %d: failed to delete rescdef file %s from %s", - pbs_errno, hookfile, minfo->mi_host); - log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_WARNING, msg_daemonname, log_buffer); + pbs_asprintf(&msgbuf, + "errno %d: failed to delete rescdef file %s from %s", + pbs_errno, hookfile, minfo->mi_host); + log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_WARNING, msg_daemonname, msgbuf); + free(msgbuf); } else { - - snprintf(log_buffer, sizeof(log_buffer), - "successfully deleted rescdef file %s from %s:%d", hookfile, - minfo->mi_host, minfo->mi_port); - log_event(PBSEVENT_DEBUG, PBS_EVENTCLASS_REQUEST, LOG_INFO, msg_daemonname, log_buffer); + pbs_asprintf(&msgbuf, + "successfully deleted rescdef file %s from %s:%d", + hookfile, minfo->mi_host, minfo->mi_port); + log_event(PBSEVENT_DEBUG, PBS_EVENTCLASS_REQUEST, LOG_INFO, msg_daemonname, msgbuf); + free(msgbuf); /* Delete all SEND_RESCDEF action */ /* so it doesn't get retried for this */ /* "deleted" resourcdef. */ @@ -5784,22 +5801,26 @@ post_sendhookRPP(struct work_task *pwt) } if (event == MOM_HOOK_ACTION_SEND_RESCDEF) { - snprintf(hookfile, MAXPATHLEN, "%s%s", path_hooks, pact->hookname); + snprintf(hookfile, sizeof(hookfile), "%.*s%.*s", + (int)(sizeof(hookfile) - PBS_HOOK_NAME_SIZE), path_hooks, + PBS_HOOK_NAME_SIZE, pact->hookname); if ((rc != 0) && (pbs_errno != PBSE_MOM_REJECT_ROOT_SCRIPTS)) { - snprintf(log_buffer, sizeof(log_buffer), - "errno %d: failed to copy rescdef file %s to %s:%d", - pbs_errno, hookfile, minfo->mi_host, minfo->mi_port); - log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_WARNING, msg_daemonname, log_buffer); + pbs_asprintf(&msgbuf, + "errno %d: failed to copy rescdef file %s to %s:%d", + pbs_errno, hookfile, minfo->mi_host, minfo->mi_port); + log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_WARNING, msg_daemonname, msgbuf); + free(msgbuf); } else { if (rc != PBSE_MOM_REJECT_ROOT_SCRIPTS) { - snprintf(log_buffer, sizeof(log_buffer), - "successfully sent rescdef file %s to %s:%d", hookfile, - minfo->mi_host, minfo->mi_port); - log_event(PBSEVENT_DEBUG, PBS_EVENTCLASS_REQUEST, LOG_INFO, msg_daemonname, log_buffer); + pbs_asprintf(&msgbuf, + "successfully sent rescdef file %s to %s:%d", + hookfile, minfo->mi_host, minfo->mi_port); + log_event(PBSEVENT_DEBUG, PBS_EVENTCLASS_REQUEST, LOG_INFO, msg_daemonname, msgbuf); + free(msgbuf); } else { snprintf(log_buffer, sizeof(log_buffer), - "warning: sending resourcedef to %s:%d got rejected (mom's reject_root_scripts=1)", - minfo->mi_host, minfo->mi_port); + "warning: sending resourcedef to %s:%d got rejected (mom's reject_root_scripts=1)", + minfo->mi_host, minfo->mi_port); log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_INFO, msg_daemonname, log_buffer); } pact->action &= ~(MOM_HOOK_ACTION_SEND_RESCDEF); @@ -5808,41 +5829,49 @@ post_sendhookRPP(struct work_task *pwt) } if (event == MOM_HOOK_ACTION_DELETE) { - snprintf(hookfile, MAXPATHLEN, "%s%s", pact->hookname, HOOK_FILE_SUFFIX); + snprintf(hookfile, sizeof(hookfile), "%.*s%s", + (int)(sizeof(hookfile) - strlen(HOOK_FILE_SUFFIX) - 1), + pact->hookname, HOOK_FILE_SUFFIX); if (rc != 0) { - snprintf(log_buffer, sizeof(log_buffer), - "errno %d: failed to delete hook file %s from %s", - pbs_errno, hookfile, minfo->mi_host); - log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_WARNING, msg_daemonname, log_buffer); + pbs_asprintf(&msgbuf, + "errno %d: failed to delete hook file %s from %s", + pbs_errno, hookfile, minfo->mi_host); + log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_WARNING, msg_daemonname, msgbuf); + free(msgbuf); } else { - snprintf(log_buffer, sizeof(log_buffer), - "successfully deleted hook file %s from %s:%d", hookfile, - minfo->mi_host, minfo->mi_port); - log_event(PBSEVENT_DEBUG, PBS_EVENTCLASS_REQUEST, LOG_INFO, msg_daemonname, log_buffer); - + pbs_asprintf(&msgbuf, + "successfully deleted hook file %s from %s:%d", + hookfile, minfo->mi_host, minfo->mi_port); + log_event(PBSEVENT_DEBUG, PBS_EVENTCLASS_REQUEST, LOG_INFO, msg_daemonname, msgbuf); + free(msgbuf); pact->action &= ~MOM_HOOK_ACTION_DELETE; hook_track_save((mominfo_t *) minfo, j); } } if (event == MOM_HOOK_ACTION_SEND_ATTRS) { - snprintf(hookfile, MAXPATHLEN, "%s%s%s", path_hooks, pact->hookname, HOOK_FILE_SUFFIX); + snprintf(hookfile, sizeof(hookfile), "%.*s%.*s%s", + (int)(sizeof(hookfile) - PBS_HOOK_NAME_SIZE - strlen(HOOK_FILE_SUFFIX)), + path_hooks, PBS_HOOK_NAME_SIZE, pact->hookname, HOOK_FILE_SUFFIX); if ((rc != 0) && (pbs_errno != PBSE_MOM_REJECT_ROOT_SCRIPTS)) { - snprintf(log_buffer, sizeof(log_buffer), - "errno %d: failed to copy hook file %s to %s:%d", - pbs_errno, hookfile, minfo->mi_host, minfo->mi_port); - log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_WARNING, msg_daemonname, log_buffer); + pbs_asprintf(&msgbuf, + "errno %d: failed to copy hook file %s to %s:%d", + pbs_errno, hookfile, minfo->mi_host, minfo->mi_port); + log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_WARNING, msg_daemonname, msgbuf); + free(msgbuf); } else { if (pbs_errno != PBSE_MOM_REJECT_ROOT_SCRIPTS) { - snprintf(log_buffer, sizeof(log_buffer), - "successfully sent hook file %s to %s:%d", hookfile, - minfo->mi_host, minfo->mi_port); - log_event(PBSEVENT_DEBUG, PBS_EVENTCLASS_REQUEST, LOG_INFO, msg_daemonname, log_buffer); + pbs_asprintf(&msgbuf, + "successfully sent hook file %s to %s:%d", + hookfile, minfo->mi_host, minfo->mi_port); + log_event(PBSEVENT_DEBUG, PBS_EVENTCLASS_REQUEST, LOG_INFO, msg_daemonname, msgbuf); + free(msgbuf); } else { - snprintf(log_buffer, sizeof(log_buffer), - "warning: sending hook file %s to %s:%d got rejected (mom's reject_root_scripts=1)", - hookfile, minfo->mi_host, minfo->mi_port); - log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_INFO, msg_daemonname, log_buffer); + pbs_asprintf(&msgbuf, + "warning: sending hook file %s to %s:%d got rejected (mom's reject_root_scripts=1)", + hookfile, minfo->mi_host, minfo->mi_port); + log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_INFO, msg_daemonname, msgbuf); + free(msgbuf); } pact->action &= ~(MOM_HOOK_ACTION_SEND_ATTRS); hook_track_save((mominfo_t *) minfo, j); @@ -5850,23 +5879,28 @@ post_sendhookRPP(struct work_task *pwt) } if (event == MOM_HOOK_ACTION_SEND_CONFIG) { - snprintf(hookfile, MAXPATHLEN, "%s%s%s", path_hooks, pact->hookname, HOOK_CONFIG_SUFFIX); + snprintf(hookfile, sizeof(hookfile), "%.*s%.*s%s", + (int)(sizeof(hookfile) - PBS_HOOK_NAME_SIZE - strlen(HOOK_CONFIG_SUFFIX)), + path_hooks, PBS_HOOK_NAME_SIZE, pact->hookname, HOOK_CONFIG_SUFFIX); if ((rc != 0) && (pbs_errno != PBSE_MOM_REJECT_ROOT_SCRIPTS)) { - snprintf(log_buffer, sizeof(log_buffer), - "errno %d: failed to copy hook file %s to %s:%d", - pbs_errno, hookfile, minfo->mi_host, minfo->mi_port); - log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_WARNING, msg_daemonname, log_buffer); + pbs_asprintf(&msgbuf, + "errno %d: failed to copy hook file %s to %s:%d", + pbs_errno, hookfile, minfo->mi_host, minfo->mi_port); + log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_WARNING, msg_daemonname, msgbuf); + free(msgbuf); } else { if (pbs_errno != PBSE_MOM_REJECT_ROOT_SCRIPTS) { - snprintf(log_buffer, sizeof(log_buffer), - "successfully sent hook file %s to %s:%d", hookfile, - minfo->mi_host, minfo->mi_port); - log_event(PBSEVENT_DEBUG, PBS_EVENTCLASS_REQUEST, LOG_INFO, msg_daemonname, log_buffer); + pbs_asprintf(&msgbuf, + "successfully sent hook file %s to %s:%d", + hookfile, minfo->mi_host, minfo->mi_port); + log_event(PBSEVENT_DEBUG, PBS_EVENTCLASS_REQUEST, LOG_INFO, msg_daemonname, msgbuf); + free(msgbuf); } else { - snprintf(log_buffer, sizeof(log_buffer), - "warning: sending hook file %s to %s:%d got rejected (mom's reject_root_scripts=1)", - hookfile, minfo->mi_host, minfo->mi_port); - log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_INFO, msg_daemonname, log_buffer); + pbs_asprintf(&msgbuf, + "warning: sending hook file %s to %s:%d got rejected (mom's reject_root_scripts=1)", + hookfile, minfo->mi_host, minfo->mi_port); + log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_INFO, msg_daemonname, msgbuf); + free(msgbuf); } pact->action &= ~(MOM_HOOK_ACTION_SEND_CONFIG); hook_track_save((mominfo_t *) minfo, j); @@ -5874,23 +5908,28 @@ post_sendhookRPP(struct work_task *pwt) } if (event == MOM_HOOK_ACTION_SEND_SCRIPT) { - snprintf(hookfile, MAXPATHLEN, "%s%s%s", path_hooks, pact->hookname, HOOK_SCRIPT_SUFFIX); + snprintf(hookfile, sizeof(hookfile), "%.*s%.*s%s", + (int)(sizeof(hookfile) - PBS_HOOK_NAME_SIZE - strlen(HOOK_SCRIPT_SUFFIX)), + path_hooks, PBS_HOOK_NAME_SIZE, pact->hookname, HOOK_SCRIPT_SUFFIX); if ((rc != 0) && (pbs_errno != PBSE_MOM_REJECT_ROOT_SCRIPTS)) { - snprintf(log_buffer, sizeof(log_buffer), - "errno %d: failed to copy hook file %s to %s:%d", - pbs_errno, hookfile, minfo->mi_host, minfo->mi_port); - log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_WARNING, msg_daemonname, log_buffer); + pbs_asprintf(&msgbuf, + "errno %d: failed to copy hook file %s to %s:%d", + pbs_errno, hookfile, minfo->mi_host, minfo->mi_port); + log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_WARNING, msg_daemonname, msgbuf); + free(msgbuf); } else { if (pbs_errno != PBSE_MOM_REJECT_ROOT_SCRIPTS) { - snprintf(log_buffer, sizeof(log_buffer), - "successfully sent hook file %s to %s:%d", hookfile, - minfo->mi_host, minfo->mi_port); - log_event(PBSEVENT_DEBUG, PBS_EVENTCLASS_REQUEST, LOG_INFO, msg_daemonname, log_buffer); + pbs_asprintf(&msgbuf, + "successfully sent hook file %s to %s:%d", + hookfile, minfo->mi_host, minfo->mi_port); + log_event(PBSEVENT_DEBUG, PBS_EVENTCLASS_REQUEST, LOG_INFO, msg_daemonname, msgbuf); + free(msgbuf); } else { - snprintf(log_buffer, sizeof(log_buffer), - "warning: sending hook file %s to %s:%d got rejected (mom's reject_root_scripts=1)", - hookfile, minfo->mi_host, minfo->mi_port); - log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_INFO, msg_daemonname, log_buffer); + pbs_asprintf(&msgbuf, + "warning: sending hook file %s to %s:%d got rejected (mom's reject_root_scripts=1)", + hookfile, minfo->mi_host, minfo->mi_port); + log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_REQUEST, LOG_INFO, msg_daemonname, msgbuf); + free(msgbuf); } pact->action &= ~(MOM_HOOK_ACTION_SEND_SCRIPT); hook_track_save((mominfo_t *) minfo, j); @@ -5955,7 +5994,7 @@ check_add_hook_mcast_info(int conn, mominfo_t *minfo, char *hookname, int action return NULL; if (add_mom_deferred_list(conn, minfo, post_sendhookRPP, - dup_msgid, minfo, info) == NULL) { + dup_msgid, minfo, info) == NULL) { free(info); free(dup_msgid); return NULL; @@ -5976,7 +6015,7 @@ check_add_hook_mcast_info(int conn, mominfo_t *minfo, char *hookname, int action tmp = realloc(g_hook_mcast_array, sizeof(hook_mcast_info_t) * (g_hook_mcast_array_len + 1)); if (!tmp) { - log_err(-1, NULL, "Could not allocate array of hook info"); + log_err(-1, __func__, "Could not allocate array of hook info"); return NULL; } g_hook_mcast_array = tmp; @@ -5993,7 +6032,7 @@ check_add_hook_mcast_info(int conn, mominfo_t *minfo, char *hookname, int action return NULL; if (add_mom_deferred_list(conn, minfo, post_sendhookRPP, - strdup(g_hook_mcast_array[i].msgid), minfo, info) == NULL) { + strdup(g_hook_mcast_array[i].msgid), minfo, info) == NULL) { free(info); return NULL; } @@ -6202,7 +6241,7 @@ sync_mom_hookfilesRPP(void *minfo) if (!phook || (phook->event & MOM_EVENTS) == 0) pact->action &= ~MOM_HOOK_ACTION_SEND_SCRIPT; else if (!check_add_hook_mcast_info(conn, minfo_array[i], pact->hookname, - MOM_HOOK_ACTION_SEND_SCRIPT, j)) + MOM_HOOK_ACTION_SEND_SCRIPT, j)) ret = SYNC_HOOKFILES_FAIL; } @@ -6226,37 +6265,26 @@ sync_mom_hookfilesRPP(void *minfo) int filetype; if (g_hook_mcast_array[i].action == MOM_HOOK_ACTION_DELETE_RESCDEF) { - - strncpy(hookfile, hookname, sizeof(hookfile)); + snprintf(hookfile, sizeof(hookfile), "%s", hookname); cmd = 1; filetype = 1; - } else if (g_hook_mcast_array[i].action & MOM_HOOK_ACTION_SEND_RESCDEF) { - snprintf(hookfile, sizeof(hookfile), "%s%s", path_hooks, hookname); cmd = 2; filetype = 1; - } else if (g_hook_mcast_array[i].action & MOM_HOOK_ACTION_DELETE) { - snprintf(hookfile, sizeof(hookfile), "%s%s", hookname, HOOK_FILE_SUFFIX); cmd = 1; filetype = 2; - } else if (g_hook_mcast_array[i].action & MOM_HOOK_ACTION_SEND_ATTRS) { - snprintf(hookfile, sizeof(hookfile), "%s%s%s", path_hooks, hookname, HOOK_FILE_SUFFIX); cmd = 2; filetype = 2; - } else if (g_hook_mcast_array[i].action & MOM_HOOK_ACTION_SEND_CONFIG) { - snprintf(hookfile, sizeof(hookfile), "%s%s%s", path_hooks, hookname, HOOK_CONFIG_SUFFIX); cmd = 2; filetype = 2; - } else if (g_hook_mcast_array[i].action & MOM_HOOK_ACTION_SEND_SCRIPT) { - snprintf(hookfile, sizeof(hookfile), "%s%s%s", path_hooks, hookname, HOOK_SCRIPT_SUFFIX); cmd = 2; filetype = 2; @@ -6270,8 +6298,8 @@ sync_mom_hookfilesRPP(void *minfo) if (cmd == 1) { if (PBSD_delhookfile(mconn, hookfile, 1, &msgid) != 0) { snprintf(log_buffer, sizeof(log_buffer), - "errno %d: failed to multicast deletion of %s file %s", - pbs_errno, ((filetype == 1) ? "rscdef":"hook"), hookfile); + "errno %d: failed to multicast deletion of %s file %s", + pbs_errno, ((filetype == 1) ? "rscdef":"hook"), hookfile); log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_SERVER, LOG_INFO, __func__, log_buffer); rc = -1; @@ -6291,8 +6319,8 @@ sync_mom_hookfilesRPP(void *minfo) rc = 0; } else if (rc != 0) { snprintf(log_buffer, sizeof(log_buffer), - "errno %d: failed to multicast copy %s file %s", - pbs_errno, ((filetype == 1) ? "rscdef":"hook"), hookfile); + "errno %d: failed to multicast copy %s file %s", + pbs_errno, ((filetype == 1) ? "rscdef":"hook"), hookfile); log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_SERVER, LOG_INFO, __func__, log_buffer); rc = -1; } else { @@ -6368,7 +6396,7 @@ kill_sync_hook_process(void) } #else if (kill(g_sync_hook_pid, SIGKILL) == -1) { - log_err(errno, "kill_sync_mom_hook_process", "error killing pid"); + log_err(errno, __func__, "error killing pid"); return; } #endif @@ -6499,7 +6527,6 @@ bg_sync_mom_hookfiles(void) /* * the child process - * */ /* standard rpp closure and net close */ @@ -6709,11 +6736,11 @@ next_sync_mom_hookfiles(void) /* we're timing out previous sync mom hook files process/action */ if (pbs_conf.pbs_use_tcp == 1) { snprintf(log_buffer, sizeof(log_buffer), - "Timing out previous send of mom hook updates " - "(send replies expected=%d received=%d)", - g_hook_replies_expected, g_hook_replies_recvd); + "Timing out previous send of mom hook updates " + "(send replies expected=%d received=%d)", + g_hook_replies_expected, g_hook_replies_recvd); log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_SERVER, - LOG_INFO, __func__, log_buffer); + LOG_INFO, __func__, log_buffer); snprintf(log_buffer, sizeof(log_buffer), "timeout_sec=%lu", timeout_sec); log_event(PBSEVENT_DEBUG4, PBS_EVENTCLASS_SERVER, LOG_INFO, __func__, log_buffer); @@ -6724,7 +6751,7 @@ next_sync_mom_hookfiles(void) "Timing out previous send of mom hook updates " "(killing child process %d)", g_sync_hook_pid); log_event(PBSEVENT_DEBUG3, PBS_EVENTCLASS_SERVER, - LOG_INFO, __func__, log_buffer); + LOG_INFO, __func__, log_buffer); kill_sync_hook_process(); } /* attempt collapsing the hook tracking file */ @@ -6751,7 +6778,7 @@ void mark_mom_hooks_seen(void) { - if (mom_hooks_seen < 0) { /* should not happen */ + if (mom_hooks_seen < 0) { /* should not happen */ log_event(PBSEVENT_DEBUG2, PBS_EVENTCLASS_HOOK, LOG_INFO, __func__, "mom_hooks_seen went negative, resetting to 0"); @@ -6808,9 +6835,11 @@ bg_delete_mom_hooks(void *minfo) #endif if (pbs_conf.pbs_use_tcp == 1) { - /* add_pending* and sync_mom_hookfiles() use the 'path_hooks_tracking */ - /* file for recording the hook actions to perform and their */ - /* outcome. */ + /* + * add_pending* and sync_mom_hookfiles() use the + * path_hooks_tracking file for recording the hook + * actions to perform and their outcome. + */ add_pending_mom_allhooks_action(minfo, MOM_HOOK_ACTION_DELETE); add_pending_mom_hook_action(minfo, PBS_RESCDEF, MOM_HOOK_ACTION_DELETE_RESCDEF); @@ -6832,7 +6861,6 @@ bg_delete_mom_hooks(void *minfo) /* * the child process - * */ /* standard rpp closure and net close */ @@ -6857,9 +6885,11 @@ bg_delete_mom_hooks(void *minfo) path_hooks_tracking = (char *)path_hooks_tracking_tmp; - /* add_pending* and sync_mom_hookfiles() use the 'path_hooks_tracking */ - /* file for recording the hook actions to perform and their */ - /* outcome. */ + /* + * add_pending* and sync_mom_hookfiles() use the + * path_hooks_tracking file for recording the hook + * actions to perform and their outcome. + */ add_pending_mom_allhooks_action(minfo, MOM_HOOK_ACTION_DELETE); add_pending_mom_hook_action(minfo, PBS_RESCDEF, MOM_HOOK_ACTION_DELETE_RESCDEF); @@ -6903,14 +6933,18 @@ bg_delete_mom_hooks(void *minfo) "%s%s%s.%ld", path_hooks_workdir, PBS_TRACKING, HOOK_TRACKING_SUFFIX, time(NULL)); path_hooks_tracking = (char *)path_hooks_tracking_tmp; - /* add_pending* and pbs_send_hooks prgram use the */ - /* 'path_hooks_tracking file for recording the hook actions */ - /* to perform and their outcome. */ + /* + * add_pending* and pbs_send_hooks prgram use the + * path_hooks_tracking file for recording the hook + * actions to perform and their outcome. + */ add_pending_mom_allhooks_action(minfo, MOM_HOOK_ACTION_DELETE); add_pending_mom_hook_action(minfo, PBS_RESCDEF, MOM_HOOK_ACTION_DELETE_RESCDEF); - /* restore original 'path_hooks_tracking' value, since on Windows, */ - /* this is still the main server */ + /* + * restore original 'path_hooks_tracking' value, since + * on Windows, this is still the main server + */ path_hooks_tracking = path_hooks_tracking_save; sprintf(buf, "path_hooks_tracking=%s\n", path_hooks_tracking_tmp); win_pwrite(&pio, buf, strlen(buf)); @@ -6998,7 +7032,7 @@ get_server_hook_results(char *input_file, int *accept_flag, int *reject_flag, ch char *line_data = NULL; int line_data_sz; long int endpos; - char hook_euser[PBS_MAXUSER + 1] = {0}; + char hook_euser[PBS_MAXUSER + 1] = {'\0'}; int arg_list_entries = 0; int b_triple_quotes = 0; int e_triple_quotes = 0; @@ -7103,14 +7137,11 @@ get_server_hook_results(char *input_file, int *accept_flag, int *reject_flag, ch jj = strlen(line_data); if ((line_data[jj - 1] != '\n') && - (ftell(fp) != endpos)) { - /* get more input for - * current item. - */ + (ftell(fp) != endpos)) { + /* get more input for current item. */ continue; } - e_triple_quotes = - ends_with_triple_quotes(line_data, 0); + e_triple_quotes = ends_with_triple_quotes(line_data, 0); if (e_triple_quotes) { break; @@ -7344,7 +7375,7 @@ get_server_hook_results(char *input_file, int *accept_flag, int *reject_flag, ch save_characteristic(pnode); rc = mgr_set_attr(pnode->nd_attr, node_attr_def, ND_ATR_LAST, - plist, ATR_DFLAG_WRACC, &bad, (void *)pnode, ATR_ACTION_ALTER); + plist, ATR_DFLAG_WRACC, &bad, (void *)pnode, ATR_ACTION_ALTER); if (rc != 0) { pbse_err = pbse_to_txt(rc); snprintf(raw_err, sizeof(raw_err), "%d", rc); @@ -7357,7 +7388,7 @@ get_server_hook_results(char *input_file, int *accept_flag, int *reject_flag, ch update_db |= ndtype_flag; mgr_log_attr(msg_man_set, plist, - PBS_EVENTCLASS_NODE, pnode->nd_name, NULL); + PBS_EVENTCLASS_NODE, pnode->nd_name, NULL); } } free_svrattrl(plist); @@ -7447,7 +7478,7 @@ post_server_periodic_hook(struct work_task *ptask) return; } if (WIFEXITED(stat)) { - char reject_msg[HOOK_MSG_SIZE + 1] = {0}; + char reject_msg[HOOK_MSG_SIZE + 1] = {'\0'}; char *next_time_str; int hook_error_flag = 0; @@ -7621,8 +7652,8 @@ run_periodic_hook(struct work_task *ptask) req_ptr.resv_list = (pbs_list_head *)get_resv_list(); ret = server_process_hooks(PBS_BATCH_HookPeriodic, NULL, NULL, phook, - HOOK_EVENT_PERIODIC, NULL, &req_ptr, hook_msg, - sizeof(hook_msg), pbs_python_set_interrupt, &num_run, &event_initialized); + HOOK_EVENT_PERIODIC, NULL, &req_ptr, hook_msg, + sizeof(hook_msg), pbs_python_set_interrupt, &num_run, &event_initialized); if (ret == 0) log_event(PBSE_HOOKERROR, PBS_EVENTCLASS_HOOK, LOG_ERR, __func__, hook_msg); diff --git a/src/server/job_func.c b/src/server/job_func.c index 5a6fc9d2e8d..cb8ae985c4a 100644 --- a/src/server/job_func.c +++ b/src/server/job_func.c @@ -1004,8 +1004,7 @@ find_job(char *jobid) char buf[PBS_MAXSVRJOBID+1]; /* Make a copy of the job ID string before we modify it. */ - strncpy(buf, jobid, sizeof(buf)); - buf[PBS_MAXSVRJOBID] = '\0'; + snprintf(buf, sizeof(buf), "%s", jobid); /* * If @server_name was specified, it was used to route the * request to this server. It will not be part of the string diff --git a/src/server/job_recov.c b/src/server/job_recov.c index 6aca92dd262..c0815a31e63 100644 --- a/src/server/job_recov.c +++ b/src/server/job_recov.c @@ -932,8 +932,7 @@ job_or_resv_recov_fs(char *filename, int objtype) attribute_def *p_attr_def = NULL; int final_attr; int attr_unkn; - char namebuf[MAXPATHLEN]; - char err_buf[80]; + char namebuf[MAXPATHLEN + 1]; if (objtype == RESC_RESV_OBJECT) { @@ -989,7 +988,7 @@ job_or_resv_recov_fs(char *filename, int objtype) fds = open(namebuf, O_RDONLY, 0); if (fds < 0) { sprintf(log_buffer, "%s on %s", err_msg, namebuf); - log_err(errno, "job_or_resv_recov", log_buffer); + log_err(errno, __func__, log_buffer); free((char *)pobj); return NULL; } @@ -1000,8 +999,9 @@ job_or_resv_recov_fs(char *filename, int objtype) /* read in job or resc_resv quick save sub-structure */ if (read(fds, (char *)p_fixed, fixed_size) != fixed_size) { - (void)sprintf(err_buf, "problem reading %s", namebuf); - log_err(errno, "job_or_resv_recov", err_buf); + char err_buf[MAXPATHLEN + 32]; + snprintf(err_buf, sizeof(err_buf), "problem reading %s", namebuf); + log_err(errno, __func__, err_buf); free((char *)pobj); (void)close(fds); return NULL; @@ -1015,7 +1015,7 @@ job_or_resv_recov_fs(char *filename, int objtype) pn = strrchr(namebuf, (int)'\\'); if (pn == NULL) { sprintf(log_buffer, "bad path %s", namebuf); - log_err(errno, "job_or_resv_recov", log_buffer); + log_err(errno, __func__, log_buffer); free((char *)pj); (void)close(fds); return NULL; @@ -1026,10 +1026,12 @@ job_or_resv_recov_fs(char *filename, int objtype) #endif if (strncmp(pn, prefix, strlen(prefix)) != 0) { - /* mismatch, discard job (reservation) */ + char *msgbuf; - (void)sprintf(log_buffer, ptcs, pobjID, namebuf); - log_err(-1, "job_or_resv_recov", log_buffer); + /* mismatch, discard job (reservation) */ + pbs_asprintf(&msgbuf, ptcs, pobjID, namebuf); + log_err(-1, __func__, msgbuf); + free(msgbuf); free((char *)pobj); (void)close(fds); return NULL; @@ -1040,7 +1042,7 @@ job_or_resv_recov_fs(char *filename, int objtype) if (recov_attr_fs(fds, pobj, p_attr_def, wattr, final_attr, attr_unkn) != 0) { - log_err(errno, "job_or_resv_recov", "error from recov_attr"); + log_err(errno, __func__, "error from recov_attr"); if (objtype == RESC_RESV_OBJECT) { #ifndef PBS_MOM /*MOM doesn't know about resource reservations*/ diff --git a/src/server/node_manager.c b/src/server/node_manager.c index 23b8bc729a6..49d696e0686 100644 --- a/src/server/node_manager.c +++ b/src/server/node_manager.c @@ -297,12 +297,12 @@ comp_keys(u_long key1, u_long key2, struct tree *pt) mominfo_t * tfind2(const u_long key1, const u_long key2, struct tree **rootp) { - int i; - if (rootp == NULL) return NULL; while (*rootp != NULL) { /* Knuth's T1: */ + int i; + i = comp_keys(key1, key2, *rootp); if (i == 0) return (*rootp)->momp; /* we found it! */ @@ -491,7 +491,6 @@ static void set_all_state(mominfo_t *pmom, int do_set, unsigned long bits, char *txt, enum Set_All_State_When setwhen) { - int do_this_vnode; int imom; unsigned long mstate; mom_svrinfo_t *psvrmom = (mom_svrinfo_t *)(pmom->mi_data); @@ -514,6 +513,7 @@ set_all_state(mominfo_t *pmom, int do_set, unsigned long bits, char *txt, } for (nchild = 0; nchild < psvrmom->msr_numvnds; ++nchild) { + int do_this_vnode; do_this_vnode = 1; @@ -778,9 +778,6 @@ post_discard_job(job *pjob, mominfo_t *pmom, int newstate) { char *downmom = NULL; struct jbdscrd *pdsc; - static char ndtext[] = "Job deleted, execution node %s down"; - static char ndreque[] = "Job requeued, execution node %s down"; - static char nddown[] = "Job never started, execution node %s down"; if (pjob->ji_discard == NULL) return; @@ -817,6 +814,8 @@ post_discard_job(job *pjob, mominfo_t *pmom, int newstate) pjob->ji_discard = NULL; if ((pjob->ji_qs.ji_state == JOB_STATE_QUEUED) && (pjob->ji_qs.ji_substate == JOB_SUBSTATE_QUEUED)) { + static char nddown[] = "Job never started, execution node %s down"; + /* * The job was rejected by mother superior and has * already been placed back in queued state by a @@ -833,6 +832,8 @@ post_discard_job(job *pjob, mominfo_t *pmom, int newstate) } if (pjob->ji_qs.ji_substate == JOB_SUBSTATE_RERUN3) { + static char ndreque[] = "Job requeued, execution node %s down"; + /* * Job to be rerun, no need to check if job is rerunnable * because to get here the job is either rerunnable or Mom @@ -860,8 +861,6 @@ post_discard_job(job *pjob, mominfo_t *pmom, int newstate) /* at this point the job is to be purged */ if (pjob->ji_acctrec) { - char *pc; - /* fairly normal job exit, record accounting info */ account_job_update(pjob, PBS_ACCT_LAST); account_jobend(pjob, pjob->ji_acctrec, PBS_ACCT_END); @@ -869,10 +868,11 @@ post_discard_job(job *pjob, mominfo_t *pmom, int newstate) if (server.sv_attr[(int)SRV_ATR_log_events].at_val.at_long & PBSEVENT_JOB_USAGE) { /* log events set to record usage */ - log_event(PBSEVENT_JOB_USAGE | PBSEVENT_JOB_USAGE, - PBS_EVENTCLASS_JOB, LOG_INFO, + log_event(PBSEVENT_JOB_USAGE, PBS_EVENTCLASS_JOB, LOG_INFO, pjob->ji_qs.ji_jobid, pjob->ji_acctrec); } else { + char *pc; + /* no usage in log, truncate messge */ if ((pc = strchr(pjob->ji_acctrec, (int)' ')) != NULL) *pc = '\0'; @@ -881,6 +881,8 @@ post_discard_job(job *pjob, mominfo_t *pmom, int newstate) } } else { + static char ndtext[] = "Job deleted, execution node %s down"; + sprintf(log_buffer, ndtext, downmom); log_event(PBSEVENT_JOB, PBS_EVENTCLASS_JOB, LOG_INFO, pjob->ji_qs.ji_jobid, log_buffer); @@ -1106,11 +1108,9 @@ mom_ping_need(mominfo_t *pmom, int force_hello, int once) mom_svrinfo_t *psvrmom = (mom_svrinfo_t *)(pmom->mi_data); struct pbsnode *np; struct pbssubn *snp; - unsigned int port; int do_ping = 0; int nchild; int com; - vnpool_mom_t *ppool; if (psvrmom->msr_state & INUSE_INIT) { /* Mom has been sent IS_CLUSTER_KEY/IS_HOST_TO_VNODE */ @@ -1163,6 +1163,8 @@ mom_ping_need(mominfo_t *pmom, int force_hello, int once) } if (psvrmom->msr_stream < 0) { + unsigned int port; + port = pmom->mi_rmport; if ((psvrmom->msr_state & INUSE_DOWN) == 0) momptr_down(pmom, "ping no stream"); @@ -1211,6 +1213,8 @@ mom_ping_need(mominfo_t *pmom, int force_hello, int once) if (com == IS_HELLO) { /* know that a HELLO is needed, but with or without inventory? */ if (psvrmom->msr_vnode_pool != 0) { + vnpool_mom_t *ppool; + ppool = find_vnode_pool(pmom); if (ppool != NULL) { /* We found the vnode_pool matching this mom. @@ -1436,7 +1440,6 @@ void set_vnode_state(struct pbsnode *pnode, unsigned long state_bits, enum vnode_state_op type) { unsigned long nd_prev_state; - char str_val[STR_TIME_SZ]; int time_int_val; time_int_val = time_now; @@ -1475,6 +1478,8 @@ set_vnode_state(struct pbsnode *pnode, unsigned long state_bits, enum vnode_stat } if (nd_prev_state != pnode->nd_state) { + char str_val[STR_TIME_SZ]; + snprintf(str_val, sizeof(str_val), "%d", time_int_val); set_attr_svr(&(pnode->nd_attr[(int)ND_ATR_last_state_change_time]), &node_attr_def[(int) ND_ATR_last_state_change_time], str_val); @@ -2181,7 +2186,6 @@ find_vnode_in_execvnode(char *big, char *little) { char *s; int patt_length; - ptrdiff_t index; if (big == NULL) return 0; @@ -2201,6 +2205,7 @@ find_vnode_in_execvnode(char *big, char *little) * node1, is skipped by catching the index value being 0. */ while (s != NULL) { + ptrdiff_t index; /* Get the index in the original string at which the occurrence is found * using pointer arithmetic. */ @@ -2427,15 +2432,15 @@ stat_update(int stream) static void recv_job_obit(int stream) { - int njobs; - int rc; - struct resc_used_update *prused; + int njobs; + int rc; njobs = disrui(stream, &rc); /* number of jobs in update */ if (rc) return; while (njobs--) { + struct resc_used_update *prused; /* IMPORTANT NOTE */ /* allocate resc_used_update here, but leave it to job_obit() */ @@ -2544,12 +2549,10 @@ ack_obit(int stream, char *jobid) static void send_discard_job(int stream, char *jobid, int runver, char *txt) { - mominfo_t *mp; - int rc; - static char sdjfmt[] = "Discard running job, %s %s"; - DBPRT(("discard_job %s\n", jobid)) if (stream != -1) { + static char sdjfmt[] = "Discard running job, %s %s"; + int rc; if ((rc = is_compose(stream, IS_DISCARD_JOB)) == DIS_SUCCESS) { if ((rc = diswst(stream, jobid)) == DIS_SUCCESS) @@ -2557,6 +2560,8 @@ send_discard_job(int stream, char *jobid, int runver, char *txt) rpp_flush(stream); } if (rc != DIS_SUCCESS) { + mominfo_t *mp; + if (txt == NULL) txt = ""; sprintf(log_buffer, sdjfmt, txt, "failed"); @@ -2612,7 +2617,6 @@ discard_job(job *pjob, char *txt, int noack) struct pbsnode *pnode; int rc; int rver; - int s; if ((pjob->ji_wattr[(int)JOB_ATR_exec_vnode].at_flags & ATR_VFLAG_SET) == 0) { /* no exec_vnode list from which to work */ @@ -2687,8 +2691,10 @@ discard_job(job *pjob, char *txt, int noack) rver = pjob->ji_wattr[(int)JOB_ATR_run_version].at_val.at_long; /* Send discard message to each Mom that is up or mark the entry down */ - for (i=0; ijdcd_mom->mi_data))->msr_stream; + for (i = 0; i < nmom; i++) { + int s; + + s = ((mom_svrinfo_t *)((pdsc + i)->jdcd_mom->mi_data))->msr_stream; if ((s != -1) && ((pdsc+i)->jdcd_state != JDCD_DOWN)) { send_discard_job(s, pjob->ji_qs.ji_jobid, rver, txt); txt = NULL; /* so one log message only */ @@ -3012,7 +3018,6 @@ is_parent_mom_of_node(mominfo_t *pmom, pbsnode *pnode) static void deallocate_job(mominfo_t *pmom, job *pjob) { - pbsnode *pnode; int i; int totcpus = 0; int totcpus0 = 0; @@ -3032,6 +3037,8 @@ deallocate_job(mominfo_t *pmom, job *pjob) return; for (i = 0; i < svr_totnodes; i++) { + pbsnode *pnode; + pnode = pbsndlist[i]; if ((pnode != NULL) && !(pnode->nd_state & INUSE_DELETED) @@ -3194,9 +3201,6 @@ void ping_nodes(struct work_task *ptask) { int i; - int mtfd_ishello; - int mtfd_isnull; - int mtfd_ishello_no_inv; int once = 0; DBPRT(("%s: entered\n", __func__)) @@ -3212,6 +3216,10 @@ ping_nodes(struct work_task *ptask) * established handler */ if (tpp_network_up == 1) { + int mtfd_ishello; + int mtfd_isnull; + int mtfd_ishello_no_inv; + /* open the tpp mcast channel here */ if ((mtfd_ishello = tpp_mcast_open()) == -1) { log_err(-1, __func__, "Failed to open TPP mcast channel for mom pings"); @@ -3609,7 +3617,6 @@ update2_to_vnode(vnal_t *pvnal, int new, mominfo_t *pmom, int *madenew, int from int i; int j; int localmadenew = 0; - int ret; struct pbsnode *pnode; pbs_list_head atrlist; svrattrl *pal; @@ -3626,10 +3633,8 @@ update2_to_vnode(vnal_t *pvnal, int new, mominfo_t *pmom, int *madenew, int from mom_svrinfo_t *pcursvrm; vnpool_mom_t *ppool; static char *cannot_def_resc = "error: resource %s for vnode %s cannot be defined"; - int pnode_has_mom = 0; char *p; char hook_name[HOOK_BUF_SIZE+1]; - char hook_buf[HOOK_BUF_SIZE+1]; int vn_state_updates = 0; int vn_resc_added = 0; @@ -3713,8 +3718,10 @@ update2_to_vnode(vnal_t *pvnal, int new, mominfo_t *pmom, int *madenew, int from * actually owns the vnode. If it does not, do not crosslink and return an error. */ if (from_hook) { + int pnode_has_mom = 0; + /* see if the node already has this Mom listed,if not add her */ - for (i=0; ind_nummoms; ++i) { + for (i = 0; i < pnode->nd_nummoms; ++i) { if (pnode->nd_moms[i] == pmom) pnode_has_mom = 1; break; @@ -3736,6 +3743,8 @@ update2_to_vnode(vnal_t *pvnal, int new, mominfo_t *pmom, int *madenew, int from if (ppool != NULL) { for (j=0; jvnpm_nummoms; ++j) { if (ppool->vnpm_moms[j] != NULL) { + int ret; + if ((ret = cross_link_mom_vnode(pnode, ppool->vnpm_moms[j])) != 0) { /* deal with error */ return (ret); @@ -3992,9 +4001,8 @@ update2_to_vnode(vnal_t *pvnal, int new, mominfo_t *pmom, int *madenew, int from strncpy(hook_name, p, HOOK_BUF_SIZE); } if (strcmp(psrp->vna_val, "1") == 0) { - - snprintf(hook_buf, - sizeof(hook_buf), + char hook_buf[sizeof(hook_name) + 40]; + snprintf(hook_buf, sizeof(hook_buf), "offlined by hook '%s' due to hook error", hook_name); mark_node_offline_by_mom(pnode->nd_name, hook_buf); @@ -5632,15 +5640,12 @@ write_single_node_state(struct pbsnode *np) { static char *offline_str = NULL; static int offline_str_sz = 0; - int sz = 0; char *tmp_str = NULL; - char *p; int isoff; int hascomment; int hascurrentaoe; pbs_db_attr_info_t attr; pbs_db_obj_info_t obj; - char offline_bits[5]; extern char *get_vnode_state_str(char *); DBPRT(("write_single_node_state: entered\n")) @@ -5651,7 +5656,11 @@ write_single_node_state(struct pbsnode *np) isoff = np->nd_state & (INUSE_OFFLINE | INUSE_OFFLINE_BY_MOM | INUSE_SLEEP); if (isoff) { - sprintf(offline_bits, "%d", isoff); + int sz; + char *p; + char offline_bits[8]; + + snprintf(offline_bits, sizeof(offline_bits), "%d", isoff); p = get_vnode_state_str(offline_bits); if (!p) { log_err(errno, "write_single_node_state", "Could not decode offline bit"); @@ -6196,14 +6205,12 @@ cvt_nodespec_to_select(char *str, char **cvt_bp, size_t *cvt_lenp, attribute *pa char *globs; int i; u_Long memamt = 0; - long nc; int nt; char *nspec; int num = 1; /*default: a request for 1 node*/ struct node_req node_req; char *pcvt; size_t pcvt_free; - size_t needed; resource *pncpus; resource *pmem; struct prop *prop = NULL; /*assume sub-spec calls out no proper */ @@ -6212,8 +6219,6 @@ cvt_nodespec_to_select(char *str, char **cvt_bp, size_t *cvt_lenp, attribute *pa char sprintf_buf[BUFSIZ]; static resource_def *pncpusdef = NULL; static resource_def *pmemdef = NULL; - static char *excl = "excl"; - static char *shared = "shared"; **cvt_bp = '\0'; pcvt = *cvt_bp; @@ -6244,6 +6249,8 @@ cvt_nodespec_to_select(char *str, char **cvt_bp, size_t *cvt_lenp, attribute *pa if ((globs = strchr(nspec, '#')) != NULL) { char *cp; char *hold; + static char *excl = "excl"; + static char *shared = "shared"; *globs++ = '\0'; globs = strdup(globs); @@ -6296,6 +6303,9 @@ cvt_nodespec_to_select(char *str, char **cvt_bp, size_t *cvt_lenp, attribute *pa if ((pncpus->rs_value.at_flags & (ATR_VFLAG_SET | ATR_VFLAG_DEFLT)) == ATR_VFLAG_SET) { + + long nc; + /* ncpus is already set and not a default */ nc = pncpus->rs_value.at_val.at_long; @@ -6327,6 +6337,8 @@ cvt_nodespec_to_select(char *str, char **cvt_bp, size_t *cvt_lenp, attribute *pa } while (*str) { + size_t needed; + node_req.nr_ppn = 1; node_req.nr_cpp = 1; node_req.nr_np = 1; @@ -6639,8 +6651,6 @@ static int set_old_job_index(struct pbsnode *pnode, job *pjob, int slot) { int i; - size_t newn; - size_t oldn; job **pnew; mom_svrinfo_t *psm; @@ -6649,6 +6659,8 @@ set_old_job_index(struct pbsnode *pnode, job *pjob, int slot) /* see if the slot exists in the array */ if (slot >= psm->msr_jbinxsz) { + size_t oldn; + size_t newn; /* slot doesn't exist, need to expand array */ @@ -6661,7 +6673,7 @@ set_old_job_index(struct pbsnode *pnode, job *pjob, int slot) "could not realloc memory for adding job index"); return -1; } - for (i=oldn; imsr_jobindx = pnew; psm->msr_jbinxsz = newn; @@ -6956,14 +6968,11 @@ set_nodes(void *pobj, int objtype, char *execvnod_in, char **execvnod_out, char int alloc_how = INUSE_JOB; char *chunk; int setck; - size_t ehlen; - size_t ehlen2; char *execvncopy; int hasprn; /* set if chunk grouped in parenthesis */ int hostcpus; int i; char *last; - int ncpus; char *execvnod = NULL; int ndindex; int nelem; @@ -6974,17 +6983,12 @@ set_nodes(void *pobj, int objtype, char *execvnod_in, char **execvnod_out, char job *pjob = NULL; char *pc; char *pc2; - resource_def *prsdef; - resource *pplace; int share_job = VNS_UNSET; - int share_node; char *vname; struct jobinfo *jp; resc_resv *presv = NULL; - attribute *patresc; /* ptr to job/resv resource_list */ int tc; /* num of nodes being allocated */ struct pbssubn *snp; - struct pbssubn *lst_sn; struct pbsnode *pnode; struct key_value_pair *pkvp; struct howl { @@ -7000,8 +7004,6 @@ set_nodes(void *pobj, int objtype, char *execvnod_in, char **execvnod_out, char static size_t ehbufsz2 = 0; static char *ehbuf = NULL; static char *ehbuf2 = NULL; - int cpu_licenses_needed = 0; - int cur_licneed = 0; attribute deallocated_attr; if (ehbufsz == 0) { @@ -7021,6 +7023,10 @@ set_nodes(void *pobj, int objtype, char *execvnod_in, char **execvnod_out, char } if (objtype == JOB_OBJECT) { + attribute *patresc; /* ptr to job/resv resource_list */ + resource *pplace; + resource_def *prsdef; + pjob = (job *)pobj; patresc = &pjob->ji_wattr[(int)JOB_ATR_resource]; @@ -7258,6 +7264,10 @@ set_nodes(void *pobj, int objtype, char *execvnod_in, char **execvnod_out, char /* now we have an array of the required nodes */ if (objtype == JOB_OBJECT) { + int cur_licneed; + int cpu_licenses_needed; + size_t ehlen; + size_t ehlen2; /* FOR JOBS ... */ @@ -7350,8 +7360,8 @@ set_nodes(void *pobj, int objtype, char *execvnod_in, char **execvnod_out, char * is specified. */ - for (i=0; ihw_pnd; @@ -7378,6 +7388,9 @@ set_nodes(void *pobj, int objtype, char *execvnod_in, char **execvnod_out, char jp->job = pjob; } } else { + struct pbssubn *lst_sn; + int ncpus; + lst_sn = NULL; for (ncpus = 0; ncpus < (phowl+i)->hw_ncpus; ncpus++) { @@ -7580,7 +7593,6 @@ set_nodes(void *pobj, int objtype, char *execvnod_in, char **execvnod_out, char void free_nodes(job *pjob) { - int numcpus; /* for floating licensing */ struct pbssubn *np; mom_svrinfo_t *psvrmom; struct pbsnode *pnode; @@ -7640,7 +7652,6 @@ free_nodes(job *pjob) for (ivnd = 0; ivnd < psvrmom->msr_numvnds; ++ivnd) { pnode = psvrmom->msr_children[ivnd]; - numcpus = 0; still_has_jobs = 0; for (np = pnode->nd_psn; np; np = np->next) { @@ -7661,7 +7672,6 @@ free_nodes(job *pjob) prev->next = next; if (jp->has_cpu) { pnode->nd_nsnfree++; /* up count of free */ - numcpus++; if (pnode->nd_nsnfree > pnode->nd_nsn) { log_event(PBSEVENT_SYSTEM, PBS_EVENTCLASS_NODE, LOG_ALERT, @@ -7703,7 +7713,6 @@ free_nodes(job *pjob) deallocate_cpu_licenses(pjob); is_called_by_job_purge = 0; - } /** @@ -8222,12 +8231,13 @@ clear_node_offline_by_mom(char *nodename, char *why) void shutdown_nodes(void) { - mominfo_t *pmom; mom_svrinfo_t *psvrmom; int i, ret; DBPRT(("%s: entered\n", __func__)) - for (i=0; ind_state & (INUSE_OFFLINE|INUSE_OFFLINE_BY_MOM)) != 0 || (pn->nd_state & INUSE_UNRESOLVABLE) != 0) { @@ -8560,9 +8574,6 @@ set_last_used_time_node(void *pobj, int type) char *last_pn = NULL; struct pbsnode *pnode; int rc; - int cmp_ret; - job *pjob; - resc_resv *presv; char str_val[STR_TIME_SZ]; int time_int_val; @@ -8572,14 +8583,20 @@ set_last_used_time_node(void *pobj, int type) return; if (type) { + resc_resv *presv; + presv = pobj; pn = parse_plus_spec(presv->ri_wattr[(int)RESV_ATR_resv_nodes].at_val.at_str, &rc); } else { + job *pjob; + pjob = pobj; pn = parse_plus_spec(pjob->ji_wattr[(int)JOB_ATR_exec_vnode].at_val.at_str, &rc); } while (pn) { + int cmp_ret; + pc = pn; while ((*pc != '\0') && (*pc != ':')) ++pc; diff --git a/src/server/pbsd_init.c b/src/server/pbsd_init.c index ea461834050..e7c970b1da8 100644 --- a/src/server/pbsd_init.c +++ b/src/server/pbsd_init.c @@ -619,7 +619,7 @@ pbsd_init(int type) rc |= chk_file_sec(pbs_conf.pbs_environment, 0, 0, S_IWGRP|S_IWOTH, 1); #endif /* WIN32 */ if (rc) { - log_err(-1, "pbsd_init", "chk_file_sec has a failure"); + log_err(-1, __func__, "chk_file_sec has a failure"); return (3); } #endif /* not DEBUG and not NO_SECURITY_CHECK */ @@ -629,7 +629,7 @@ pbsd_init(int type) rc = setup_resc(1); if (rc != 0) { /* log_buffer set in setup_resc */ - log_err(-1, "pbsd_init(setup_resc)", log_buffer); + log_err(-1, __func__, log_buffer); /* return value of -1 means a fatal error, -2 means errors * were "auto-corrected" */ if (rc == -1) @@ -661,7 +661,7 @@ pbsd_init(int type) /* Open the server database (save file) and read it in */ if ((rc != 0) || ((rc =svr_recov_db()) == -1)) { - log_err(rc, "pbsd_init", msg_init_baddb); + log_err(rc, __func__, msg_init_baddb); return (-1); } if (server.sv_attr[(int)SRV_ATR_resource_assn].at_flags & @@ -689,7 +689,7 @@ pbsd_init(int type) /* now do sched db */ rc = sched_recov_db(); if (rc == -1) { - log_err(rc, "pbsd_init", "unable to recover scheddb"); + log_err(rc, __func__, "unable to recover scheddb"); } else if(rc == -2) { /* No Schedulers found in DB */ /* Create and save default to DB*/ @@ -798,7 +798,7 @@ pbsd_init(int type) /* 6. open accounting file */ if (acct_open(acct_file) != 0) { - log_err(-1, "pbsd_init", "Could not open accounting file"); + log_err(-1, __func__, "Could not open accounting file"); return (-1); } @@ -831,7 +831,7 @@ pbsd_init(int type) state = pbs_db_cursor_init(conn, &obj, NULL); if (state == NULL) { sprintf(log_buffer, "%s", (char *) conn->conn_db_err); - log_err(-1, "pbsd_init", log_buffer); + log_err(-1, __func__, log_buffer); pbs_db_cursor_close(conn, state); (void) pbs_db_end_trx(conn, PBS_DB_ROLLBACK); return (-1); @@ -871,7 +871,7 @@ pbsd_init(int type) /* Open and read in node list if one exists */ if ((rc = setup_nodes()) == -1) { /* log_buffer set in setup_nodes */ - log_err(-1, "pbsd_init(setup_nodes)", log_buffer); + log_err(-1, __func__, log_buffer); return (-1); } mark_which_queues_have_nodes(); @@ -899,7 +899,7 @@ pbsd_init(int type) state = pbs_db_cursor_init(conn, &obj, NULL); if (state == NULL) { sprintf(log_buffer, "%s", (char *) conn->conn_db_err); - log_err(-1, "pbsd_init", log_buffer); + log_err(-1, __func__, log_buffer); pbs_db_cursor_close(conn, state); (void) pbs_db_end_trx(conn, PBS_DB_ROLLBACK); return (-1); @@ -954,7 +954,7 @@ pbsd_init(int type) state = pbs_db_cursor_init(conn, &obj, NULL); if (state == NULL) { sprintf(log_buffer, "%s", (char *) conn->conn_db_err); - log_err(-1, "pbsd_init", log_buffer); + log_err(-1, __func__, log_buffer); pbs_db_cursor_close(conn, state); (void) pbs_db_end_trx(conn, PBS_DB_ROLLBACK); return (-1); @@ -974,7 +974,7 @@ pbsd_init(int type) /* remove the loaded job from db */ if (pbs_db_delete_obj(conn, &obj) != 0) { sprintf(log_buffer, "job %s not purged", dbjob.ji_jobid); - log_err(-1, "pbsd_init", log_buffer); + log_err(-1, __func__, log_buffer); } } else { sprintf(log_buffer, "Failed to recover job %s", dbjob.ji_jobid); @@ -1149,7 +1149,7 @@ pbsd_init(int type) fd = open(path_track, O_RDONLY | O_CREAT, 0600); if (fd < 0) { - log_err(errno, "pbsd_init", "unable to open tracking file"); + log_err(errno, __func__, "unable to open tracking file"); return (-1); } #if !defined(DEBUG) && !defined(NO_SECURITY_CHECK) @@ -1221,7 +1221,7 @@ pbsd_init(int type) fd = open(path_prov_track, O_RDONLY | O_CREAT, 0600); if (fd < 0) { - log_err(errno, "pbsd_init", "unable to open prov_tracking file"); + log_err(errno, __func__, "unable to open prov_tracking file"); return (-1); } #if !defined(DEBUG) && !defined(NO_SECURITY_CHECK) @@ -1252,7 +1252,7 @@ pbsd_init(int type) server.sv_provtracksize = server.sv_attr[(int)SRV_ATR_max_concurrent_prov].at_val.at_long; - DBPRT(("pbsd_init: server.sv_provtracksize=%d amt=%ld\n", server.sv_provtracksize, (long)amt)) + DBPRT(("%s: server.sv_provtracksize=%d amt=%ld\n", __func__, server.sv_provtracksize, (long)amt)) p = malloc(amt + 1); if (p == NULL) { @@ -1384,7 +1384,7 @@ pbsd_init(int type) #ifdef WIN32 /* Under WIN32, create structure that will be used to track child processes. */ if (initpids() == 0) { - log_err(-1, "pbsd_init", "Creating pid handles table failed!"); + log_err(-1, __func__, "Creating pid handles table failed!"); return (-1); } #endif @@ -1856,7 +1856,7 @@ pbsd_init_job(job *pjob, int type) static int pbsd_init_reque(job *pjob, int change_state) { - char logbuf[265]; + char logbuf[384]; int newstate; int newsubstate; int rc; diff --git a/src/server/pbsd_main.c b/src/server/pbsd_main.c index 1480bd5e524..6ccfdf646e5 100644 --- a/src/server/pbsd_main.c +++ b/src/server/pbsd_main.c @@ -485,7 +485,6 @@ do_rpp(int stream) void rpp_request(int fd) { - int stream; int iloop; int rpp_max_pkt_check = RPP_MAX_PKT_CHECK_DEFAULT; @@ -500,6 +499,8 @@ rpp_request(int fd) rpp_max_pkt_check = server.sv_attr[(int) SRV_ATR_rpp_max_pkt_check].at_val.at_long; for (iloop = 0; iloop < rpp_max_pkt_check; iloop++) { + int stream; + if ((stream = rpp_poll()) == -1) { #ifdef WIN32 /* workaround to a win2k winsock bug */ @@ -574,7 +575,6 @@ void pbs_close_stdfiles(void) { static int already_done = 0; - FILE *dummyfile; #ifdef WIN32 #define NULL_DEVICE "nul" #else @@ -582,6 +582,8 @@ pbs_close_stdfiles(void) #endif if (!already_done) { + FILE *dummyfile; + (void)fclose(stdin); (void)fclose(stdout); (void)fclose(stderr); @@ -1540,10 +1542,10 @@ main(int argc, char **argv) fprintf(stderr, "."); #endif try_connect_database(conn); - if (conn->conn_state == PBS_DB_CONNECT_STATE_CONNECTED) + if (conn && (conn->conn_state == PBS_DB_CONNECT_STATE_CONNECTED)) break; - if (conn && conn->conn_db_state == PBS_DB_DOWN) { + if (conn && (conn->conn_db_state == PBS_DB_DOWN)) { /* db start failed, reset everything, so we try all over again */ pbs_db_disconnect(conn); pbs_db_destroy_connection(conn); @@ -1719,7 +1721,7 @@ main(int argc, char **argv) if ((sock = init_network(pbs_server_port_dis)) < 0) { (void) sprintf(log_buffer, - "init_network failed using ports Server:%d Scheduler:%d MOM:%d RM:%d", + "init_network failed using ports Server:%u Scheduler:%u MOM:%u RM:%u", pbs_server_port_dis, pbs_scheduler_port, pbs_mom_port, pbs_rm_port); log_event(PBSEVENT_SYSTEM | PBSEVENT_ADMIN, PBS_EVENTCLASS_SERVER, LOG_ERR, msg_daemonname, log_buffer); @@ -1981,7 +1983,8 @@ main(int argc, char **argv) /* save it so we can free it without needing the pointer inside svr_interp_data */ keep_daemon_name = svr_interp_data.daemon_name; - strncpy(svr_interp_data.local_host_name, server_host, (sizeof(svr_interp_data.local_host_name) - 1)); + snprintf(svr_interp_data.local_host_name, sizeof(svr_interp_data.local_host_name), + "%s", server_host); if ((pc=strchr(svr_interp_data.local_host_name, '.')) != NULL) *pc = '\0'; @@ -2340,13 +2343,13 @@ main(int argc, char **argv) static int get_port(char *arg, unsigned int *port, pbs_net_t *addr) { - char *name; - if (*arg == ':') ++arg; if (isdigit((int)*arg)) { /* port only specified */ *port = (unsigned int)atoi(arg); } else { + char *name; + name = parse_servername(arg, port); if (name) { *addr = get_hostaddr(name); @@ -2354,7 +2357,7 @@ get_port(char *arg, unsigned int *port, pbs_net_t *addr) return (-1); } } - if ((*port <= 0) || (*addr == 0)) + if ((*port == 0) || (*addr == 0)) return (-1); return 0; } @@ -2638,12 +2641,13 @@ main(int argc, char *argv[]) { 0, 0 } }; if (getenv("PBS_CONF_FILE") == NULL) { - char conf_path[80]; char *p; - char psave; - struct stat sbuf; if (p = strstr(argv[0], "exec")) { + struct stat sbuf; + char psave; + char conf_path[80]; + psave = *p; *p = '\0'; _snprintf(conf_path, 79, "%spbs.conf", argv[0]); @@ -2967,9 +2971,11 @@ start_db() static void try_connect_database(pbs_db_conn_t *conn) { - int i; int failcode = 0; + if (conn == NULL) + return; + if (conn->conn_state == PBS_DB_CONNECT_STATE_CONNECTED) return; /* already connected */ @@ -3001,6 +3007,8 @@ try_connect_database(pbs_db_conn_t *conn) } } if (conn->conn_db_state == PBS_DB_STARTED || conn->conn_db_state == PBS_DB_STARTING) { + int i; + i = MAX_DB_RETRIES; /* * call pbs_db_connect_async a few times in a tight loop @@ -3039,7 +3047,6 @@ void stop_db() { char *db_err = NULL; - int rc = 0; pbs_db_disconnect(svr_db_conn); pbs_db_destroy_connection(svr_db_conn); @@ -3048,6 +3055,8 @@ stop_db() /* check status of db, shutdown if up */ db_oper_failed_times = 0; while (1) { + int rc; + rc = pbs_status_db(&db_err); if (rc != 0) { free(db_err); @@ -3127,7 +3136,7 @@ setup_db_connection(char *host, int timeout, int have_db_control) { int failcode = 0; char errmsg[PBS_MAX_DB_CONN_INIT_ERR + 1] = {0}; - pbs_db_conn_t *lconn = NULL; + pbs_db_conn_t *lconn; lconn = pbs_db_init_connection(host, timeout, have_db_control, &failcode, errmsg, PBS_MAX_DB_CONN_INIT_ERR); if (!lconn) { diff --git a/src/server/queue_func.c b/src/server/queue_func.c index 00d9a661c1f..85642b0ea8f 100644 --- a/src/server/queue_func.c +++ b/src/server/queue_func.c @@ -121,7 +121,7 @@ que_alloc(char *name) CLEAR_HEAD(pq->qu_jobs); CLEAR_LINK(pq->qu_link); - strncpy(pq->qu_qs.qu_name, name, PBS_MAXQUEUENAME); + snprintf(pq->qu_qs.qu_name, PBS_MAXQUEUENAME, "%s", name); append_link(&svr_queues, &pq->qu_link, pq); server.sv_qs.sv_numque++; diff --git a/src/server/req_delete.c b/src/server/req_delete.c index 1aae4a84c35..f965dcdff25 100644 --- a/src/server/req_delete.c +++ b/src/server/req_delete.c @@ -306,7 +306,7 @@ issue_delete(job *pjob) if ((at = strchr(pjob->ji_wattr[JOB_ATR_in_queue].at_val.at_str, (int)'@')) == NULL) return; - strncpy(rmt_server, at + 1, PBS_MAXSERVERNAME + 1); + snprintf(rmt_server, sizeof(rmt_server), "%s", at + 1); preq = alloc_br(PBS_BATCH_DeleteJob); if (preq == NULL) @@ -888,7 +888,7 @@ req_deleteReservation(struct batch_request *preq) struct batch_request *newreq; struct work_task *pwt; - char buf[256]; /*temp, possibly remove in future*/ + char buf[PBS_MAXHOSTNAME + PBS_MAXUSER + 2]; /* temp, possibly remove in future */ char user[PBS_MAXUSER + 1]; char host[PBS_MAXHOSTNAME + 1]; int perm; diff --git a/src/server/req_modify.c b/src/server/req_modify.c index a8943e161d6..7d6dfead81f 100644 --- a/src/server/req_modify.c +++ b/src/server/req_modify.c @@ -149,7 +149,6 @@ req_modifyjob(struct batch_request *preq) { int add_to_am_list = 0; /* if altered during sched cycle */ int bad = 0; - int i; int jt; /* job type */ int newstate; int newsubstate; @@ -237,6 +236,7 @@ req_modifyjob(struct batch_request *preq) running = 1; } while (plist) { + int i; i = find_attr(job_attr_def, plist->al_name, JOB_ATR_LAST); @@ -731,13 +731,11 @@ req_modifyReservation(struct batch_request *preq) { char *rid = NULL; svrattrl *psatl = NULL; - int index; attribute_def *pdef = NULL; int rc = 0; int bad = 0; - char buf[256] = {0}; - char buf1[PBS_MAXUSER+ PBS_MAXHOSTNAME + 2] = {0}; - int sock = preq->rq_conn; + char buf[PBS_MAXUSER + PBS_MAXHOSTNAME + 32] = {0}; + int sock; int resc_access_perm_save = 0; int send_to_scheduler = 0; int log_len = 0; @@ -750,6 +748,8 @@ req_modifyReservation(struct batch_request *preq) if (preq == NULL) return; + sock = preq->rq_conn; + presv = chk_rescResv_request(preq->rq_ind.rq_modify.rq_objname, preq); /* Note: on failure, chk_rescResv_request invokes req_reject * appropriate reply is sent and batch_request is freed. @@ -785,6 +785,8 @@ req_modifyReservation(struct batch_request *preq) while (psatl) { long temp = 0; char *end = NULL; + int index; + /* identify the attribute by name */ index = find_attr(resv_attr_def, psatl->al_name, RESV_ATR_LAST); if (index < 0) { @@ -910,6 +912,7 @@ req_modifyReservation(struct batch_request *preq) if ((presv->ri_wattr[RESV_ATR_interactive].at_flags & ATR_VFLAG_SET) == 0) { + char buf1[PBS_MAXUSER + PBS_MAXHOSTNAME + 32] = {0}; /*Not "interactive" so don't wait on scheduler, reply now*/ sprintf(buf, "%s ALTER REQUESTED", presv->ri_qs.ri_resvID); diff --git a/src/server/req_quejob.c b/src/server/req_quejob.c index 30884d21e74..c49eab0624a 100644 --- a/src/server/req_quejob.c +++ b/src/server/req_quejob.c @@ -297,23 +297,19 @@ req_quejob(struct batch_request *preq) int set_project = 0; int i; attribute tempattr; - char buf[256]; char jidbuf[PBS_MAXSVRJOBID+1]; pbs_queue *pque; char *qname; char *result; - int l; resource_def *prdefnod; resource_def *prdefsel; resource_def *prdefplc; - resource_def *prdefbad; resource *presc; conn_t *conn; attribute temp_attr; #else mom_hook_input_t hook_input; mom_hook_output_t hook_output; - char basename[MAXPATHLEN+1]; int hook_errcode = 0; int hook_rc = 0; char hook_buf[HOOK_MSG_SIZE]; @@ -571,6 +567,8 @@ req_quejob(struct batch_request *preq) /* unlink job from svr_alljobs since will be place on newjobs */ delete_link(&pj->ji_alljobs); } else { + char basename[MAXPATHLEN + 1]; + /* if not already here, allocate job struct */ if ((pj = job_alloc()) == NULL) { @@ -739,6 +737,8 @@ req_quejob(struct batch_request *preq) */ if (created_here) { /* created here */ + int l; + char buf[256]; /* check that job has a jobname */ @@ -753,6 +753,7 @@ req_quejob(struct batch_request *preq) if (pj->ji_wattr[(int)JOB_ATR_resource].at_flags & ATR_VFLAG_SET) { int have_selectplace = 0; + resource_def *prdefbad; presc = (resource *)GET_NEXT(pj->ji_wattr[(int)JOB_ATR_resource].at_val.at_list); @@ -1167,13 +1168,13 @@ req_quejob(struct batch_request *preq) /* piggy back the hook_name in the message */ /* to be stripped out by the server upon */ /* processing hook fail_action */ - snprintf(hook_msg, sizeof(hook_msg), - "%s,%s", - last_phook?last_phook->hook_name:"", - (hook_rc == 0)?hook_buf:"internal error"); + snprintf(hook_msg, sizeof(hook_msg), "%s,%.*s", + last_phook ? last_phook->hook_name : "", + (int)(sizeof(hook_msg) - (last_phook ? strlen(last_phook->hook_name) : 0) - 2), + (hook_rc == 0) ? hook_buf : "internal error"); } else { - snprintf(hook_msg, sizeof(hook_msg), - ",%s", hook_buf); + snprintf(hook_msg, sizeof(hook_msg), ",%.*s", + (int)(sizeof(hook_msg) - 2), hook_buf); } reply_text(preq, hook_errcode, hook_msg); @@ -2010,7 +2011,6 @@ req_mvjobfile(struct batch_request *preq) job *pj; #ifndef WIN32 mode_t cur_mask; - char ntmpbuf[MAXPATHLEN+1]; struct stat sb; #endif @@ -2063,9 +2063,13 @@ req_mvjobfile(struct batch_request *preq) } } if (preq->rq_ind.rq_jobfile.rq_sequence == 0) { + char ntmpbuf[MAXPATHLEN+1]; + /* receiving first piece, so create new file securely */ /* will discard any existing file (via rename) */ - strncpy(ntmpbuf, namebuf, MAXPATHLEN-6); + snprintf(ntmpbuf, sizeof(ntmpbuf), "%s", namebuf); + if (strlen(ntmpbuf) > (sizeof(ntmpbuf) - 8)) + ntmpbuf[sizeof(ntmpbuf) - 8] = '\0'; strcat(ntmpbuf, "XXXXXX"); /* template for mkstemp() */ cur_mask = umask(077); /* force to create -rw------ */ fds = mkstemp(ntmpbuf); @@ -2567,21 +2571,22 @@ locate_new_job(struct batch_request *preq, char *jobid) void req_resvSub(struct batch_request *preq) { - char buf[256]; - char buf1[PBS_MAXUSER+ PBS_MAXHOSTNAME + 2] = {0}; + /* + * buf and buf1 are used to hold user@hostname stings together + * with a small amount (less than 64 characters) of text. + */ + char buf[PBS_MAXUSER + PBS_MAXHOSTNAME + 64]; + char buf1[PBS_MAXUSER + PBS_MAXHOSTNAME + 64] = {0}; int created_here = 0; int i = 0; - int index = 0; char *rid = NULL; char ridbuf[PBS_MAXSVRRESVID+1] = {0}; - char namebuf[MAXPATHLEN+1] = {0}; char qbuf[PBS_MAXSVRRESVID+1] = {0}; char *pc = NULL; attribute_def *pdef = NULL; resc_resv *presv = NULL; svrattrl *psatl = NULL; int rc = 0; - int resv_count = 1; int sock = preq->rq_conn; char hook_msg[HOOK_MSG_SIZE] = {0}; int resc_access_perm_save = 0; @@ -2716,7 +2721,6 @@ req_resvSub(struct batch_request *preq) */ if ((presv = resc_resv_alloc()) == NULL) { - (void)unlink(namebuf); req_reject(PBSE_SYSTEM, 0, preq); return; } @@ -2743,6 +2747,7 @@ req_resvSub(struct batch_request *preq) resc_access_perm_save = resc_access_perm; /* save perm */ psatl = (svrattrl *)GET_NEXT(preq->rq_ind.rq_queuejob.rq_attr); while (psatl) { + int index; /* reservation does not support Shrink-to-fitness */ if (!(strcasecmp(psatl->al_name, ATTR_l)) && (!(strcasecmp(psatl->al_resc, MIN_WALLTIME)) || @@ -2837,6 +2842,8 @@ req_resvSub(struct batch_request *preq) * 'S' instead of 'R' */ if (presv->ri_wattr[RESV_ATR_resv_standing].at_val.at_long) { + int resv_count; + /* Check the recurrence rule. If this fails, an error message * is sent back to the requestor. Otherwise, check the number * of occurrences requested by the recurrence rule. If 1 then @@ -3026,10 +3033,7 @@ req_resvSub(struct batch_request *preq) presv->ri_wattr[RESV_ATR_euser].at_val.at_str, preq->rq_host); } - if (acl_check(&server.sv_attr[(int)SRV_ATR_AclResvUsers], - buf1, - ACL_User) == 0) { - + if (acl_check(&server.sv_attr[(int)SRV_ATR_AclResvUsers], buf1, ACL_User) == 0) { resv_free(presv); req_reject(PBSE_RESVAUTH_U, 0, preq); return; @@ -3271,15 +3275,12 @@ get_queue_for_reservation(resc_resv *presv) static int lenE = 10; /*strlen("Execution") + 1*/ static int lenF = 6; /*strlen("False") + 1*/ static int lenT = 5; /*strlen("True") + 1*/ - static char Execution[] = "Execution"; struct batch_request *newreq; attribute *pattr; pbs_list_head *plhed; int rc = 0; svrattrl *psatl; struct work_task *pwt; - resource_def *prdef; - newreq = alloc_br(PBS_BATCH_Manager); if (newreq == NULL) { @@ -3314,7 +3315,8 @@ get_queue_for_reservation(resc_resv *presv) */ j = sizeof(dont_set_in_max) / sizeof(struct dont_set_in_max); - for (i=0; ial_flags = que_attr_def[QA_ATR_QType].at_flags; strcpy(psatl->al_value, Execution); append_link(plhed, &psatl->al_link, psatl); @@ -3530,7 +3533,7 @@ act_resv_add_owner(attribute *pattr, void *pobj, int amode) enum batch_op op; resc_resv *presv; char *ps; - int len, i; + int len; if (amode != ATR_ACTION_NEW) @@ -3546,7 +3549,9 @@ act_resv_add_owner(attribute *pattr, void *pobj, int amode) ap = &presv->ri_wattr[RESV_ATR_auth_u]; if (ap->at_flags & ATR_VFLAG_SET) { - for (i=0; i < ap->at_val.at_arst->as_usedptr; ++i) + int i; + + for (i = 0; i < ap->at_val.at_arst->as_usedptr; ++i) if (!strcmp(ps, ap->at_val.at_arst->as_string[i])) return (0); /*resv owner in Authorized_Users*/ op = INCR; diff --git a/src/server/req_register.c b/src/server/req_register.c index a56a4954d87..7f08d475ac1 100644 --- a/src/server/req_register.c +++ b/src/server/req_register.c @@ -461,7 +461,8 @@ post_doq(struct work_task *pwt) destin = strchr(ppjob->ji_qs.ji_destin, (int)'@'); if (destin != NULL) { strncpy(pparent.dc_child, ppjob->ji_qs.ji_jobid, sizeof(pparent.dc_child)); - strncpy(pparent.dc_svr, destin+1, sizeof(pparent.dc_svr)); + destin++; + strncpy(pparent.dc_svr, destin, sizeof(pparent.dc_svr) - (destin - ppjob->ji_qs.ji_destin)); rc = send_depend_req(pjob, &pparent, preq->rq_ind.rq_register.rq_dependtype, JOB_DEPEND_OP_REGISTER, SYNC_SCHED_HINT_NULL, post_doq); diff --git a/src/server/req_runjob.c b/src/server/req_runjob.c index a3c6d0a1b4b..4e19fa84748 100644 --- a/src/server/req_runjob.c +++ b/src/server/req_runjob.c @@ -451,7 +451,7 @@ req_runjob(struct batch_request *preq) /* fix the job id so the suffix matches the real jobid's */ /* suffix; in case qrun 1.short vs 1.short.domain.com */ - (void)strncpy(fixjid, jid, PBS_MAXSVRJOBID); + snprintf(fixjid, sizeof(fixjid), "%s", jid); pc = strchr(fixjid, (int)'.'); if (pc) *pc = '\0'; @@ -1279,8 +1279,7 @@ post_sendmom(struct work_task *pwt) int isrpp = pwt->wt_aux2; struct batch_reply *reply = (struct batch_reply *) pwt->wt_parm3; char dest_host[PBS_MAXROUTEDEST + 1]; - char hook_name[HOOK_BUF_SIZE+1]; - char hook_buf[HOOK_BUF_SIZE+1]; + char hook_name[PBS_HOOK_NAME_SIZE + 1] = {'\0'}; char *hook_msg = NULL; if (jobp == NULL) { @@ -1299,8 +1298,6 @@ post_sendmom(struct work_task *pwt) return; /* reply must have already been handled, see job_obit */ } - hook_name[0] = '\0'; - if (!isrpp) { if (WIFEXITED(wstat)) { r = WEXITSTATUS(wstat); @@ -1355,7 +1352,7 @@ post_sendmom(struct work_task *pwt) unlink(name_buf); } } - hook_msg = parse_hook_rejectmsg(reject_msg, hook_name, HOOK_BUF_SIZE); + hook_msg = parse_hook_rejectmsg(reject_msg, hook_name, PBS_HOOK_NAME_SIZE); } } else { @@ -1435,7 +1432,7 @@ post_sendmom(struct work_task *pwt) (r == SEND_JOB_HOOK_REJECT_RERUNJOB) || (r == SEND_JOB_HOOK_REJECT_DELETEJOB)) { - hook_msg = parse_hook_rejectmsg(reject_msg, hook_name, HOOK_BUF_SIZE); + hook_msg = parse_hook_rejectmsg(reject_msg, hook_name, PBS_HOOK_NAME_SIZE); } } @@ -1514,7 +1511,7 @@ post_sendmom(struct work_task *pwt) * we dont want to copy them again; * ELSE clear exec_vnode, exec_host, etc. */ - strncpy(dest_host, jobp->ji_qs.ji_destin, sizeof(dest_host)-1); + snprintf(dest_host, sizeof(dest_host), "%s", jobp->ji_qs.ji_destin); clear_exec_on_run_fail(jobp); if (jobp->ji_qs.ji_substate != JOB_SUBSTATE_ABORT) { @@ -1580,8 +1577,14 @@ post_sendmom(struct work_task *pwt) phook = find_hook(hook_name); if (phook != NULL) { if ((phook->fail_action & HOOK_FAIL_ACTION_OFFLINE_VNODES) != 0) { - snprintf(hook_buf, - sizeof(hook_buf), + /* + * hook_buf must be large enough + * to hold the hook_name and a + * small amount of text. + */ + char hook_buf[PBS_HOOK_NAME_SIZE + 64]; + + snprintf(hook_buf, sizeof(hook_buf), "offlined by hook '%s' due to hook error", hook_name); mark_node_offline_by_mom(dest_host, hook_buf); diff --git a/src/server/svr_jobfunc.c b/src/server/svr_jobfunc.c index a9ee59d27fb..d2f8f8f9fe4 100644 --- a/src/server/svr_jobfunc.c +++ b/src/server/svr_jobfunc.c @@ -289,9 +289,10 @@ svr_enquejob(job *pjob) server.sv_qs.sv_numjobs++; server.sv_jobstates[pjob->ji_qs.ji_state]++; if (pjob->ji_qs.ji_svrflags & JOB_SVFLG_ArrayJob) { - int indx; struct ajtrkhd *ptbl = pjob->ji_ajtrk; if (ptbl) { + int indx; + for (indx = 0; indx < ptbl->tkm_ct; ++indx) set_subjob_tblstate(pjob, indx, pjob->ji_qs.ji_state); } @@ -547,7 +548,6 @@ svr_dequejob(job *pjob) { int bad_ct = 0; pbs_queue *pque; - int rc; /* remove job from server's all job list and reduce server counts */ @@ -569,7 +569,7 @@ svr_dequejob(job *pjob) } if ((pque = pjob->ji_qhdr) != NULL) { - + int rc; /* update any entity count and entity resources usage at que */ @@ -638,9 +638,7 @@ int svr_setjobstate(job *pjob, int newstate, int newsubstate) { int changed = 0; - int oldstate; pbs_queue *pque = pjob->ji_qhdr; - long newaccruetype; pbs_sched *psched; /* @@ -656,6 +654,7 @@ svr_setjobstate(job *pjob, int newstate, int newsubstate) */ if (pjob->ji_qs.ji_substate != JOB_SUBSTATE_TRANSICM) { + int oldstate; /* Not a new job, update the counts and save if needed */ @@ -734,6 +733,8 @@ svr_setjobstate(job *pjob, int newstate, int newsubstate) /* eligible_time_enable */ if (server.sv_attr[SRV_ATR_EligibleTimeEnable].at_val.at_long == 1) { + long newaccruetype; + /* determine accrue type */ newaccruetype = determine_accruetype(pjob); @@ -1256,7 +1257,7 @@ chk_wt_limits_STF(resource *resc_minwt, resource *resc_maxwt, pbs_queue *pque, a int chk_resc_limits(attribute *pattr, pbs_queue *pque) { - resource *atresc = NULL; + resource *atresc; resource *resc_maxwt = NULL; resource *resc_minwt = NULL; @@ -1830,7 +1831,6 @@ default_std(job *pjob, int key, char *to) char * prefix_std_file(job *pjob, int key) { - int len; char *name = NULL; char *outputhost; char *wdir; @@ -1841,6 +1841,8 @@ prefix_std_file(job *pjob, int key) outputhost = get_hostPart(pjob->ji_wattr[(int)JOB_ATR_job_owner].at_val.at_str); wdir = get_variable(pjob, "PBS_O_WORKDIR"); if (outputhost) { + int len; + len = strlen(outputhost) + strlen(pjob->ji_wattr[(int)JOB_ATR_jobname].at_val.at_str) + PBS_MAXSEQNUM + strlen(PBS_FILE_ARRAY_INDEX_TAG) + 6; @@ -2000,16 +2002,12 @@ set_select_and_place(int objtype, void *pobj, attribute *patr) static char *cvt = NULL; static size_t cvt_len; char *ndspec; - size_t cvtneed; - attribute_def *objatrdef; resource *presc; resource *prescsl; resource *prescpc; resource_def *prdefnd; resource_def *prdefpc; resource_def *prdefsl; - resource_def *prdefcopy; - svrattrl *psvrl; int rc; extern int resc_access_perm; @@ -2060,6 +2058,7 @@ set_select_and_place(int objtype, void *pobj, attribute *patr) } } else { + attribute_def *objatrdef; /* No nodes spec, use ncpus/mem/arch/host/software */ /* from the resource_List attribute */ @@ -2072,14 +2071,19 @@ set_select_and_place(int objtype, void *pobj, attribute *patr) CLEAR_HEAD(collectresc); resc_access_perm = READ_ONLY; if (objatrdef->at_encode(patr, &collectresc, objatrdef->at_name, NULL, ATR_ENCODE_CLIENT, NULL) > 0) { + svrattrl *psvrl; *cvt = '1'; *(cvt+1) = '\0'; psvrl = (svrattrl *)GET_NEXT(collectresc); while (psvrl) { + resource_def *prdefcopy; + prdefcopy = find_resc_def(svr_resc_def, psvrl->al_resc, svr_resc_size); if (prdefcopy && (prdefcopy->rs_flags & ATR_DFLAG_CVTSLT)) { + size_t cvtneed; + /* how much space is needed in cvt buffer, */ /* +5 = one for : = possible quotes and null */ cvtneed = strlen(psvrl->al_resc) + @@ -2377,7 +2381,6 @@ make_schedselect(attribute *patrl, resource *pselect, char *chunk; int i; int firstchunk; - int j; size_t len; int nchk; int already_set = 0; @@ -2439,6 +2442,7 @@ make_schedselect(attribute *patrl, resource *pselect, if (parse_chunk(chunk, &nchk, &nelem, &pkvp, &nchunk_internally_set) == 0) #endif /* localmod 082 */ { + int j; /* first check for any invalid resources in the select */ for (j=0; jji_qs.ji_state == JOB_STATE_RUNNING) { + static char suspend = 'S'; + static char useractive = 'U'; + if (pjob->ji_qs.ji_svrflags & JOB_SVFLG_Suspend) pjob->ji_wattr[JOB_ATR_state].at_val.at_char = suspend; else if (pjob->ji_qs.ji_svrflags & JOB_SVFLG_Actsuspd) @@ -2831,10 +2835,7 @@ state_char2int(char stc) void eval_chkpnt(attribute *jobckp, attribute *queckp) { - int jobs; - char queues[30]; char *pv; - char ckt; if (((jobckp->at_flags & ATR_VFLAG_SET) == 0) || ((queckp->at_flags & ATR_VFLAG_SET) == 0)) @@ -2842,6 +2843,10 @@ eval_chkpnt(attribute *jobckp, attribute *queckp) pv = jobckp->at_val.at_str; if ((*pv == 'c') || (*pv == 'w')) { + int jobs; + char queues[30]; + char ckt; + ckt = *pv; if (*++pv == '=') pv++; @@ -3142,16 +3147,16 @@ static void Time4reply(struct work_task *ptask) { resc_resv *presv = ptask->wt_parm1; - char buf[256] = {0}; if (presv->ri_brp) { + char buf[512] = {0}; if (presv->ri_qs.ri_state == RESV_UNCONFIRMED || presv->ri_qs.ri_state == RESV_BEING_ALTERED) - sprintf(buf, "%s UNCONFIRMED", presv->ri_qs.ri_resvID); + snprintf(buf, sizeof(buf), "%s UNCONFIRMED", presv->ri_qs.ri_resvID); else if (presv->ri_qs.ri_state == RESV_CONFIRMED) { /*Remark: this part of the if is unlikely to happen*/ /* reply would happen in req_rescreserve() */ - sprintf(buf, "%s CONFIRMED", presv->ri_qs.ri_resvID); + snprintf(buf, sizeof(buf), "%s CONFIRMED", presv->ri_qs.ri_resvID); } (void)reply_text(presv->ri_brp, PBSE_NONE, buf); @@ -3183,7 +3188,6 @@ static void Time4resv(struct work_task *ptask) { resc_resv *presv = ptask->wt_parm1; - job *pjob; int pbs_ecode; int state, sub; @@ -3196,6 +3200,7 @@ Time4resv(struct work_task *ptask) pbs_ecode = change_enableORstart(presv, Q_CHNG_START, "True"); if (!pbs_ecode) { + job *pjob; /* *this is really the line we want once the scheduler @@ -4897,29 +4902,29 @@ void resv_mailAction(resc_resv *presv, struct batch_request *preq) { int force; - char text[512]; + char text[PBS_MAXUSER + PBS_MAXHOSTNAME + 64]; - if (preq->rq_type == PBS_BATCH_DeleteResv) { + if (preq->rq_type != PBS_BATCH_DeleteResv) + return; - sprintf(text, "Requesting party: %s@%s", - preq->rq_user, preq->rq_host); + snprintf(text, sizeof(text), "Requesting party: %s@%s", + preq->rq_user, preq->rq_host); #ifdef NAS /* localmod 028 */ - /* - * The extend attribute can contain additional explanation - */ - if (preq->rq_extend) { - size_t len; - len = strlen(text); - snprintf(text+len, sizeof(text)-len, - "\nReason: %s\n", preq->rq_extend); - } -#endif /* localmod 028 */ - if (preq->rq_fromsvr != 0) - force = MAIL_FORCE; - else - force = MAIL_NORMAL; - svr_mailownerResv(presv, MAIL_ABORT, force, text); + /* + * The extend attribute can contain additional explanation + */ + if (preq->rq_extend) { + size_t len; + len = strlen(text); + snprintf(text+len, sizeof(text)-len, + "\nReason: %s\n", preq->rq_extend); } +#endif /* localmod 028 */ + if (preq->rq_fromsvr != 0) + force = MAIL_FORCE; + else + force = MAIL_NORMAL; + svr_mailownerResv(presv, MAIL_ABORT, force, text); } @@ -5171,16 +5176,11 @@ update_eligible_time(long newaccruetype, job *pjob) int alter_eligibletime(attribute *pattr, void *pobject, int actmode) { - static char *msg[] = { "initial_time", "ineligible_time", "eligible_time",\ - "run_time", "exiting" }; - char *strtime; static char errtime[] = "00:00:00"; - char logstr[256]; long timestamp = (long)time_now; /* accrual begins from here */ job * pjob = (job*)pobject; long oldaccruetype = pjob->ji_wattr[(int)JOB_ATR_accrue_type].at_val.at_long; long newaccruetype = oldaccruetype; /* We are not changing accrue type */ - long accrued_time; /* distinguish between genuine qalter and call by action */ if (actmode == ATR_ACTION_ALTER) { @@ -5188,8 +5188,18 @@ alter_eligibletime(attribute *pattr, void *pobject, int actmode) /* eligible_time_enable is OFF, then error */ if (!server.sv_attr[SRV_ATR_EligibleTimeEnable].at_val.at_long) { return PBSE_ETEERROR; - } - else { + } else { + long accrued_time; + char *strtime; + char logstr[256]; + static char *msg[] = { + "initial_time", + "ineligible_time", + "eligible_time", + "run_time", + "exiting" + }; + accrued_time = (long)time_now - pjob->ji_wattr[(int)JOB_ATR_sample_starttime].at_val.at_long; @@ -5271,7 +5281,7 @@ svr_saveorpurge_finjobhist(job *pjob) void svr_clean_job_history(struct work_task *pwt) { - job *pjob = NULL; + job *pjob; job *nxpjob = NULL; int walltime_used = 0; @@ -5546,12 +5556,11 @@ svr_setjob_histinfo(job *pjob, histjob_type type) int newsubstate = 0; struct ajtrkhd *ptbl = NULL; struct work_task *pwt = NULL; - char qname[PBS_MAXQUEUENAME+PBS_MAXHOSTNAME+1]; if (type == T_MOV_JOB) { /* MOVED job */ - char *destination = pjob->ji_qs.ji_destin; char *tmpstr = NULL; + char qname[PBS_MAXROUTEDEST + 1]; if (destination == NULL || *destination == '\0') { return; @@ -5589,7 +5598,8 @@ svr_setjob_histinfo(job *pjob, histjob_type type) if (tmpstr != NULL) { *tmpstr = '\0'; } - snprintf(pjob->ji_qs.ji_queue, PBS_MAXQUEUENAME+1, "%s", qname); + snprintf(pjob->ji_qs.ji_queue, sizeof(pjob->ji_qs.ji_queue), + "%.*s", PBS_MAXQUEUENAME, qname); /* Set the queue attribute to destination */ (void)job_attr_def[(int)JOB_ATR_in_queue].at_decode( @@ -5953,13 +5963,13 @@ find_ms_full_host_and_port(job *pjob, int *port) return NULL; } - if ((p=strchr(ms_exec_host, '/')) != NULL) + if ((p = strchr(ms_exec_host, '/')) != NULL) *p = '\0'; - if ((p=strchr(ms_exec_host, ':')) != NULL) { - *p = '\0'; - *port = atoi(p+1); - } + if ((p = strchr(ms_exec_host, ':')) != NULL) { + *p = '\0'; + *port = atoi(p + 1); + } } else if (pjob->ji_wattr[(int)JOB_ATR_exec_host].at_flags & ATR_VFLAG_SET) { ms_exec_host = strdup(pjob->ji_wattr[(int)JOB_ATR_exec_host].at_val.at_str); if (ms_exec_host == NULL) { @@ -5967,7 +5977,7 @@ find_ms_full_host_and_port(job *pjob, int *port) return NULL; } - if ((p=strchr(ms_exec_host, '/')) != NULL) + if ((p = strchr(ms_exec_host, '/')) != NULL) *p = '\0'; } return (ms_exec_host); @@ -6056,7 +6066,6 @@ post_send_job_exec_update_req(struct work_task *pwt) { struct batch_request *mom_preq = NULL; struct batch_request *cli_preq = NULL; - char err_msg[LOG_BUF_SIZE] = {0}; int bcode = 0; if (pwt == NULL) @@ -6071,6 +6080,8 @@ post_send_job_exec_update_req(struct work_task *pwt) cli_preq = pwt->wt_parm2; if (bcode) { + char err_msg[LOG_BUF_SIZE]; + /* also take note of the reject msg if any */ if (mom_preq->rq_reply.brp_choice == BATCH_REPLY_CHOICE_Text) { (void)snprintf(err_msg, sizeof(err_msg), "%s", mom_preq->rq_reply.brp_un.brp_txt.brp_str); @@ -6351,7 +6362,7 @@ resc_sum_values_action(enum resc_sum_action action, resource_def *resc_def, char } if (action == RESC_SUM_ADD) { - int l, r; + int r; struct resc_sum *tmp_rs; int found_match = 0; struct attribute tmpatr; @@ -6374,6 +6385,8 @@ resc_sum_values_action(enum resc_sum_action action, resource_def *resc_def, char } if (k == resc_sum_values_size) { + int l; + /* add a new entry */ l = resc_sum_values_size + 5; @@ -6497,7 +6510,6 @@ expand_select_spec(char *select_str) int snelma; static int snelmt = 0; /* must be static per parse_chunk_r() */ static key_value_pair *skv = NULL; /* must be static per parse_chunk_r() */ - int rc = 0; int i, j; char *psubspec; char buf[LOG_BUF_SIZE+1]; @@ -6518,6 +6530,8 @@ expand_select_spec(char *select_str) /* parse chunk from select spec */ psubspec = parse_plus_spec_r(selbuf, &last3, &hasprn3); while (psubspec) { + int rc; + #ifdef NAS /* localmod 082 */ rc = parse_chunk_r(psubspec, 0, &snc, &snelma, &snelmt, &skv, NULL); #else @@ -7335,8 +7349,8 @@ recreate_exec_vnode(job *pjob, char *vnodelist, char *err_msg, /* output message about nodes to be freed but no part of job */ if ((vnodelist != NULL) && (err_msg != NULL) && (err_msg_sz > 0)) { - char *tmpbuf = NULL; - char *tmpbuf2 = NULL; + char *tmpbuf; + char *tmpbuf2; char *pc = NULL; char *pc1 = NULL; char *save_ptr; /* posn for strtok_r() */ diff --git a/src/server/user_func.c b/src/server/user_func.c index b2033f9f6e9..a42811afa3c 100644 --- a/src/server/user_func.c +++ b/src/server/user_func.c @@ -299,7 +299,7 @@ req_usercredential(struct batch_request *preq) int type; char *cred; size_t len; - char info[512]; + char info[PBS_MAXUSER + PBS_MAXHOSTNAME + 2]; int rval; DBPRT(("%s: entered\n", __func__)) @@ -321,9 +321,7 @@ req_usercredential(struct batch_request *preq) return; } - - sprintf(info, "%s@%s", preq->rq_user, preq->rq_host); - + snprintf(info, sizeof(info), "%s@%s", preq->rq_user, preq->rq_host); #ifdef WIN32 if (strcmpi(preq->rq_user, user) != 0) { diff --git a/src/tools/pbsTclInit.c b/src/tools/pbsTclInit.c index b72c44b1b09..d38a05c3ef9 100644 --- a/src/tools/pbsTclInit.c +++ b/src/tools/pbsTclInit.c @@ -62,7 +62,7 @@ -char log_buffer[4096]; +char log_buffer[LOG_BUF_SIZE]; #ifdef NAS /* localmod 099 */ extern int quiet; #endif /* localmod 099 */ diff --git a/src/tools/pbs_ds_monitor.c b/src/tools/pbs_ds_monitor.c index fd0d80d72e5..09f48d9108c 100644 --- a/src/tools/pbs_ds_monitor.c +++ b/src/tools/pbs_ds_monitor.c @@ -70,15 +70,12 @@ #include "server_limits.h" #endif #include - #ifdef WIN32 #include #endif - #include "pbs_db.h" +#include "pbs_ifl.h" - -#define MAXPATHLEN 1024 #define MAX_LOCK_ATTEMPTS 5 #define MAX_DBPID_ATTEMPTS 20 #define TEMP_BUF_SIZE 100 diff --git a/src/tools/pbs_idled.c b/src/tools/pbs_idled.c index b7f7ce9b930..c2ad01b1c9f 100644 --- a/src/tools/pbs_idled.c +++ b/src/tools/pbs_idled.c @@ -232,7 +232,7 @@ main(int argc, char *argv[], char *envp[]) } if (pointer_query(dsp, w, &cur_xy)) - if (cur_xy.x != prev_xy.x || cur_xy.y != cur_xy.y) { + if (cur_xy.x != prev_xy.x || cur_xy.y != prev_xy.y) { do_update = 1; prev_xy = cur_xy; } diff --git a/src/tools/pbs_probe.c b/src/tools/pbs_probe.c index 9c5667b5546..8e0479ab02e 100644 --- a/src/tools/pbs_probe.c +++ b/src/tools/pbs_probe.c @@ -94,6 +94,7 @@ #include #include "cmds.h" #include "pbs_version.h" +#include "pbs_ifl.h" @@ -101,14 +102,6 @@ #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) #endif -#ifndef MAXPATHLEN -#ifdef PATHSIZE -#define MAXPATHLEN PATHSIZE -#else -#define MAXPATHLEN 1024 -#endif /* PATHSIZE */ -#endif /* MAXPATHLEN */ - #define DEMARC '/' #define DFLT_MSGTBL_SZ (1024) @@ -1206,7 +1199,6 @@ typedef struct infrastruct { struct statdata statd; } INFRA; -static const char ident[] = "@(#)"; static void am_i_authorized(void); static void infrastruct_params(struct infrastruct *, int); static void adjust_for_os(struct infrastruct *pinf); @@ -2084,19 +2076,19 @@ static int get_realpath_values(struct infrastruct *pinf) { char *real = NULL; - char path[MAXPATHLEN]; + char path[MAXPATHLEN + 1]; char *endhead; char demarc[]="/"; int i, j; MPUG *pmpug; int good_prime[PBS_last]; - char msg[1024]; + char *msgbuf; /* * First try and resolve to a real path the MPUG path * data belonging to *pinf's "pri" member */ - for (i=0; ipri.pbs_mpug[i].path) { if ((real = realpath(pinf->pri.pbs_mpug[i].path, NULL)) != NULL) { @@ -2108,19 +2100,27 @@ get_realpath_values(struct infrastruct *pinf) * system not able to convert path string to valid * file system path */ - snprintf(msg, sizeof(msg), "Unable to convert the primary, %s, string to a real path\n%s\n", origin_names[i], strerror(errno)); - put_msg_in_table(pinf, SRC_pri, MSG_pri, msg); - snprintf(msg, sizeof(msg), "%s: %s\n", origin_names[i], pinf->pri.pbs_mpug[i].path); - put_msg_in_table(pinf, SRC_pri, MSG_pri, msg); + pbs_asprintf(&msgbuf, + "Unable to convert the primary, %s, string to a real path\n%s\n", + origin_names[i], strerror(errno)); + put_msg_in_table(pinf, SRC_pri, MSG_pri, msgbuf); + free(msgbuf); + pbs_asprintf(&msgbuf, "%s: %s\n", + origin_names[i], pinf->pri.pbs_mpug[i].path); + put_msg_in_table(pinf, SRC_pri, MSG_pri, msgbuf); + free(msgbuf); /* good_prime[i] = 0; */ } } else { - if (pinf->pri.pbs_mpug[i].notReq == 0) - snprintf(msg, sizeof(msg), "Missing primary path %s", origin_names[i]); - put_msg_in_table(pinf, SRC_pri, MSG_pri, msg); + if (pinf->pri.pbs_mpug[i].notReq == 0) { + pbs_asprintf(&msgbuf, "Missing primary path %s", + origin_names[i]); + put_msg_in_table(pinf, SRC_pri, MSG_pri, msgbuf); + free(msgbuf); + } } } - for (i=0; ipri.pbs_mpug[i].notReq == 0) { print_problems(pinf); exit(0); @@ -2153,16 +2153,20 @@ get_realpath_values(struct infrastruct *pinf) if ((fd = open(path, O_RDONLY)) != -1) { if (fstat(fd, &st) != -1) { if ((st.st_mode & 0777) != 0600) { - snprintf(msg, sizeof(msg), "%s, permission must " - "be 0600\n", path); + pbs_asprintf(&msgbuf, + "%s, permission must be 0600\n", + path); put_msg_in_table(NULL, - SRC_home, MSG_real, msg); + SRC_home, MSG_real, msgbuf); + free(msgbuf); } if (st.st_uid != 0) { - snprintf(msg, sizeof(msg), "%s, owner must " - "be root\n", path); + pbs_asprintf(&msgbuf, + "%s, owner must be root\n", + path); put_msg_in_table(NULL, - SRC_home, MSG_real, msg); + SRC_home, MSG_real, msgbuf); + free(msgbuf); } if (st.st_size < sizeof(buf) && read(fd, buf, st.st_size) == @@ -2172,10 +2176,12 @@ get_realpath_values(struct infrastruct *pinf) if (pw != NULL) pbs_dataname[0] = strdup(buf); else { - snprintf(msg, sizeof(msg), "db_user %s " - "does not exist\n", buf); + pbs_asprintf(&msgbuf, + "db_user %s does not exist\n", + buf); put_msg_in_table(NULL, - SRC_home, MSG_real, msg); + SRC_home, MSG_real, msgbuf); + free(msgbuf); } } } @@ -2190,11 +2196,11 @@ get_realpath_values(struct infrastruct *pinf) strcat(path, demarc); endhead = &path[strlen(path)]; - for (i=0; ihome[i]) == NULL) continue; - for (j=0; jexec[i]) == NULL) continue; - for (j=0; jal_value == NULL) { @@ -2257,10 +2256,11 @@ main(int argc, char *argv[], char *envp[]) /* Just pass on the command line arguments onto Python */ - snprintf(python_cmdline, MAXBUF, "%s", python_path); - for (i=1; i < argc; i++) { - snprintf(python_cmdline, MAXBUF, "%s \"%s\"", - python_cmdline, argv[i]); + snprintf(python_cmdline, sizeof(python_cmdline), "%s", python_path); + for (i = 1; i < argc; i++) { + strncat(python_cmdline, " \"", sizeof(python_cmdline) - strlen(python_cmdline) - 1); + strncat(python_cmdline, argv[i], sizeof(python_cmdline) - strlen(python_cmdline) - 1); + strncat(python_cmdline, "\"", sizeof(python_cmdline) - strlen(python_cmdline) - 1); } rc = wsystem(python_cmdline, INVALID_HANDLE_VALUE); #else @@ -2272,17 +2272,17 @@ main(int argc, char *argv[], char *envp[]) #ifdef SYSTEM_PYTHON_PATH snprintf(python_path, MAXPATHLEN, "%s", SYSTEM_PYTHON_PATH); pc = strdup(SYSTEM_PYTHON_PATH); - if(pc == NULL) { + if (pc == NULL) { fprintf(stderr, "Out of memory\n"); return 1; } pc2 = strstr(pc,"bin/python"); - if(pc2 == NULL) { + if (pc2 == NULL) { fprintf(stderr, "Python executable not found!\n"); return 1; } *pc2 = '\0'; - if(strlen(pc) > 0) { + if (strlen(pc) > 0) { snprintf(python_prefix, MAXPATHLEN, "%s", pc); free(pc); } else { @@ -2399,22 +2399,22 @@ main(int argc, char *argv[], char *envp[]) char **argv2 = NULL; int argc2; int argv_len = 0; - char hook_script[MAXPATHLEN+1]; - char the_input[MAXPATHLEN+1]; - char the_output[MAXPATHLEN+1]; - char the_server_output[MAXPATHLEN+1]; - char the_data[MAXPATHLEN+1]; - char path_log[MAXPATHLEN+1]; - char logname[MAXPATHLEN+1]; - - char hook_name[MAXBUF+1]; - char req_user[PBS_MAXUSER+1]; - char req_host[PBS_MAXHOSTNAME+1]; - char hookstr_type[MAXBUF+1]; - char hookstr_event[MAXBUF+1]; + char hook_script[MAXPATHLEN + 1] = {'\0'}; + char the_input[MAXPATHLEN + 1] = {'\0'}; + char the_output[MAXPATHLEN + 1] = {'\0'}; + char the_server_output[MAXPATHLEN + 1] = {'\0'}; + char the_data[MAXPATHLEN + 1] = {'\0'}; + char path_log[MAXPATHLEN + 1] = {'\0'}; + char logname[MAXPATHLEN + 1] = {'\0'}; + + char hook_name[MAXBUF + 1] = {'\0'}; + char req_user[PBS_MAXUSER + 1] = {'\0'}; + char req_host[PBS_MAXHOSTNAME + 1] = {'\0'}; + char hookstr_type[MAXBUF + 1] = {'\0'}; + char hookstr_event[MAXBUF + 1] = {'\0'}; int hook_alarm = 0; int c, j; - int errflg=0; + int errflg = 0; unsigned int hook_event = 0; struct python_script *py_script = NULL; pbs_list_head default_list, event, event_job, event_job_o, @@ -2447,19 +2447,9 @@ main(int argc, char *argv[], char *envp[]) char *argv_str_orig = NULL; char *argv_str = NULL; int print_progname = 0; - int print_argv= 0; - int print_env= 0; - - the_input[0] = '\0'; - the_output[0] = '\0'; - the_server_output[0] = '\0'; - the_data[0] = '\0'; - hook_name[0] = '\0'; - req_user[0] = '\0'; - req_host[0] = '\0'; - hookstr_type[0] = '\0'; - hookstr_event[0] = '\0'; - hook_script[0] = '\0'; + int print_argv = 0; + int print_env = 0; + logname[0] = '\0'; strcpy(path_log, "."); @@ -2498,8 +2488,7 @@ main(int argc, char *argv[], char *envp[]) fprintf(stderr, "pbs_python: illegal -i value\n"); errflg++; } else { - strncpy(the_input, optarg, - sizeof(the_input)-1); + snprintf(the_input, sizeof(the_input), "%s", optarg); } break; case 'o': @@ -2509,8 +2498,7 @@ main(int argc, char *argv[], char *envp[]) fprintf(stderr, "pbs_python: illegal -o value\n"); errflg++; } else { - strncpy(the_output, optarg, - sizeof(the_output)-1); + snprintf(the_output, sizeof(the_output), "%s", optarg); } break; case 's': @@ -2520,8 +2508,7 @@ main(int argc, char *argv[], char *envp[]) fprintf(stderr, "pbs_python: illegal -s value\n"); errflg++; } else { - strncpy(the_data, optarg, - sizeof(the_data)-1); + snprintf(the_data, sizeof(the_data), "%s", optarg); pbs_python_set_use_static_data_value(1); } break; @@ -2532,8 +2519,7 @@ main(int argc, char *argv[], char *envp[]) fprintf(stderr, "pbs_python: illegal -L value\n"); errflg++; } else { - strncpy(path_log, optarg, - sizeof(path_log)-1); + snprintf(path_log, sizeof(path_log), "%s", optarg); } break; case 'l': @@ -2543,8 +2529,7 @@ main(int argc, char *argv[], char *envp[]) fprintf(stderr, "pbs_python: illegal -l value\n"); errflg++; } else { - strncpy(logname, optarg, - sizeof(logname)-1); + snprintf(logname, sizeof(logname), "%s", optarg); } break; case 'e': @@ -2678,7 +2663,7 @@ main(int argc, char *argv[], char *envp[]) if (strcmp(plist->al_name, "type") == 0) { hook_event = \ hookstr_event_toint(plist->al_value); - sprintf(hookstr_event, "%d", hook_event); + sprintf(hookstr_event, "%u", hook_event); } else if (strcmp(plist->al_name, "hook_name") == 0) { strcpy(hook_name, plist->al_value); } else if (strcmp(plist->al_name, "requestor") == 0) { @@ -2723,21 +2708,35 @@ main(int argc, char *argv[], char *envp[]) forward2back_slash(logname); #endif if ((logname[0] != '\0') && (!is_full_path(logname))) { - char curdir[MAXPATHLEN+1]; - char full_logname[MAXPATHLEN+1]; - char slash; + char curdir[MAXPATHLEN + 1]; + char full_logname[MAXPATHLEN + 1]; + char *slash; #ifdef WIN32 - slash = '\\'; + slash = "\\"; #else - slash = '/'; + slash = "/"; #endif /* save current working dir before any chdirs */ if (getcwd(curdir, MAXPATHLEN) == NULL) { fprintf(stderr, "getcwd failed\n"); exit(2); } - snprintf(full_logname, sizeof(full_logname), "%s%c%s", curdir, slash, logname); - strncpy(logname, full_logname, sizeof(logname)-1); + if ((strlen(curdir) + strlen(logname) + 1) >= sizeof(full_logname)) { + fprintf(stderr, "log file path too long\n"); + exit(2); + } + /* + * The following silliness is brought to you by gcc version 8. + * Having checked to ensure full_logname is large enough we + * should be able to snprintf() the entire string in one call. + * However, the bounds checking in gcc version 8 is overzealous + * and generates a format-overflow warning forcing us to use + * strcat() instead. + */ + snprintf(full_logname, sizeof(full_logname), "%s", curdir); + strncat(full_logname, slash, sizeof(full_logname) - strlen(full_logname)); + strncat(full_logname, logname, sizeof(full_logname) - strlen(full_logname)); + snprintf(logname, sizeof(logname), "%s", full_logname); } /* set python interp data */ @@ -3450,7 +3449,7 @@ main(int argc, char *argv[], char *envp[]) } pbs_python_end: if (pbs_python_get_reboot_host_flag() == TRUE) { - char *reboot_cmd = NULL; + char *reboot_cmd; fprintf(fp_out, "%s.%s=True\n", PBS_OBJ, PBS_REBOOT_OBJECT); diff --git a/src/tools/pbs_tclWrap.c b/src/tools/pbs_tclWrap.c index ec6bf6b85e1..f6662cd36de 100644 --- a/src/tools/pbs_tclWrap.c +++ b/src/tools/pbs_tclWrap.c @@ -1584,7 +1584,7 @@ char *argv[]; return TCL_OK; case 2: - strncpy(rtime, argv[1], sizeof(rtime)); + snprintf(rtime, sizeof(rtime), "%s", argv[1]); len = strlen(rtime); when = 0; if (len < 12) @@ -1662,7 +1662,7 @@ char *argv[]; t->tm_sec = 0; t->tm_isdst = -1; when = mktime(t); - strncpy(rtime, argv[2], sizeof(rtime)); + snprintf(rtime, sizeof(rtime), "%s", argv[2]); len = strlen(rtime); break; diff --git a/src/tools/pbs_upgrade_job.c b/src/tools/pbs_upgrade_job.c index 79c4169718e..fd25bb67a87 100644 --- a/src/tools/pbs_upgrade_job.c +++ b/src/tools/pbs_upgrade_job.c @@ -297,13 +297,16 @@ upgrade_job_file(int fd) /* Copy the data to the new jobfix structure */ memset(&new_job, 0, sizeof(new_job)); memcpy(&new_job.ji_qs, &old_jobfix, sizeof(old_jobfix)); - strncpy(new_job.ji_qs.ji_jobid, old_jobfix.ji_jobid, sizeof(old_jobfix.ji_jobid)); - strncpy(new_job.ji_qs.ji_fileprefix, old_jobfix.ji_fileprefix, - sizeof(old_jobfix.ji_fileprefix)); - strncpy(new_job.ji_qs.ji_queue, old_jobfix.ji_queue, sizeof(old_jobfix.ji_queue)); - strncpy(new_job.ji_qs.ji_destin, old_jobfix.ji_destin, sizeof(old_jobfix.ji_destin)); + snprintf(new_job.ji_qs.ji_jobid, sizeof(new_job.ji_qs.ji_jobid), + "%s", old_jobfix.ji_jobid); + snprintf(new_job.ji_qs.ji_fileprefix, sizeof(new_job.ji_qs.ji_fileprefix), + "%s", old_jobfix.ji_fileprefix); + snprintf(new_job.ji_qs.ji_queue, sizeof(new_job.ji_qs.ji_queue), + "%s", old_jobfix.ji_queue); + snprintf(new_job.ji_qs.ji_destin, sizeof(new_job.ji_qs.ji_destin), + "%s", old_jobfix.ji_destin); new_job.ji_qs.ji_un_type = old_jobfix.ji_un_type; - memcpy(&new_job.ji_qs.ji_un, &old_jobfix.ji_un, sizeof(old_jobfix.ji_un)); + memcpy(&new_job.ji_qs.ji_un, &old_jobfix.ji_un, sizeof(new_job.ji_qs.ji_un)); /* Open a temporary file to stage data */ tmp = tmpfile(); @@ -401,7 +404,7 @@ int upgrade_task_file(char *taskfile) { FILE *tmp = NULL; - int fd = -1; + int fd; int tmpfd = -1; int len; int ret; @@ -437,7 +440,7 @@ upgrade_task_file(char *taskfile) /* Copy the data to the new task structure */ memset(&new_task, 0, sizeof(new_task)); strncpy(new_task.ti_qs.ti_parentjobid, old_taskfix.ti_parentjobid, - sizeof(old_taskfix.ti_parentjobid)); + sizeof(new_task.ti_qs.ti_parentjobid)); new_task.ti_qs.ti_parentnode = old_taskfix.ti_parentnode; new_task.ti_qs.ti_myvnode = old_taskfix.ti_myvnode; new_task.ti_qs.ti_parenttask = old_taskfix.ti_parenttask; @@ -581,7 +584,7 @@ main(int argc, char *argv[]) } /* Ensure the tasks directory exists */ - strncpy(namebuf, jobfile, sizeof(namebuf)); + snprintf(namebuf, sizeof(namebuf), "%s", jobfile); p = strrchr(namebuf, '.'); if (!p) { fprintf(stderr, "Missing job file suffix");