diff --git a/core/log_io.c b/core/log_io.c index b4f4f97ce1f8360a14d595f06aae813c116d7d47..f41080da6391f362742111151a7745aedc44c50e 100644 --- a/core/log_io.c +++ b/core/log_io.c @@ -576,7 +576,9 @@ inprogress_log_rename(char *filename) assert(strcmp(suffix, inprogress_suffix) == 0); /* Create a new filename without '.inprogress' suffix. */ - new_filename = strndupa(filename, suffix - filename); + new_filename = alloca(suffix - filename + 1); + memcpy(new_filename, filename, suffix - filename); + new_filename[suffix - filename] = '\0'; if (rename(filename, new_filename) != 0) { say_syserror("can't rename %s to %s", filename, new_filename); diff --git a/core/tarantool.c b/core/tarantool.c index 0e6e4cac55c4e088bc3d0f3bbe2c53affd4c76ed..497cb698812592efa4970e15afc6c12132c40c39 100644 --- a/core/tarantool.c +++ b/core/tarantool.c @@ -268,6 +268,13 @@ create_pid(void) f = fopen(cfg.pid_file, "a+"); if (f == NULL) panic_syserror("can't open pid file"); + /* + * fopen() is not guaranteed to set the seek position to + * the beginning of file according to ANSI C (and, e.g., + * on FreeBSD. + */ + if (fseeko(f, 0, SEEK_SET) != 0) + panic_syserror("can't fseek to the beginning of pid file"); if (fgets(buf, sizeof(buf), f) != NULL && strlen(buf) > 0) { pid = strtol(buf, NULL, 10); @@ -275,7 +282,8 @@ create_pid(void) panic("the daemon is already running"); else say_info("updating a stale pid file"); - fseeko(f, 0, SEEK_SET); + if (fseeko(f, 0, SEEK_SET) != 0) + panic_syserror("can't fseek to the beginning of pid file"); if (ftruncate(fileno(f), 0) == -1) panic_syserror("ftruncate(`%s')", cfg.pid_file); }