Changeset: 6a77f995662e for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6a77f995662e
Modified Files:
        clients/mapiclient/mclient.c
        common/stream/stream.c
        gdk/gdk_bbp.c
        gdk/gdk_heap.c
        gdk/gdk_logger.c
        gdk/gdk_system.c
        gdk/gdk_utils.c
        monetdb5/mal/mal_import.c
        monetdb5/modules/kernel/alarm.c
        sql/backends/monet5/UDF/capi/capi.c
        sql/backends/monet5/UDF/pyapi/pyapi.c
        sql/backends/monet5/sql.c
        tools/merovingian/daemon/forkmserver.c
        tools/merovingian/daemon/merovingian.c
        tools/mserver/mserver5.c
Branch: default
Log Message:

Merge with Mar2018 branch.


diffs (truncated from 910 to 300 lines):

diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -1773,30 +1773,35 @@ start_pager(stream **saveFD)
 
                /* ignore SIGPIPE so that we get an error instead of signal */
                act.sa_handler = SIG_IGN;
-               sigemptyset(&act.sa_mask);
-               act.sa_flags = 0;
-               sigaction(SIGPIPE, &act, NULL);
-
-               p = popen(pager, "w");
-               if (p == NULL)
+               if(sigemptyset(&act.sa_mask) == -1) {
                        fprintf(stderr, "Starting '%s' failed\n", pager);
-               else {
-                       *saveFD = toConsole;
-                       /* put | in name to indicate that file should be closed 
with pclose */
-                       if ((toConsole = file_wastream(p, "|pager")) == NULL) {
-                               toConsole = *saveFD;
-                               *saveFD = NULL;
+               } else {
+                       act.sa_flags = 0;
+                       if(sigaction(SIGPIPE, &act, NULL) == -1) {
                                fprintf(stderr, "Starting '%s' failed\n", 
pager);
-                       }
+                       } else {
+                               p = popen(pager, "w");
+                               if (p == NULL)
+                                       fprintf(stderr, "Starting '%s' 
failed\n", pager);
+                               else {
+                                       *saveFD = toConsole;
+                                       /* put | in name to indicate that file 
should be closed with pclose */
+                                       if ((toConsole = file_wastream(p, 
"|pager")) == NULL) {
+                                               toConsole = *saveFD;
+                                               *saveFD = NULL;
+                                               fprintf(stderr, "Starting '%s' 
failed\n", pager);
+                                       }
 #ifdef HAVE_ICONV
-                       if (encoding != NULL) {
-                               if ((toConsole = iconv_wstream(toConsole, 
encoding, "pager")) == NULL) {
-                                       toConsole = *saveFD;
-                                       *saveFD = NULL;
-                                       fprintf(stderr, "Starting '%s' 
failed\n", pager);
+                                       if (encoding != NULL) {
+                                               if ((toConsole = 
iconv_wstream(toConsole, encoding, "pager")) == NULL) {
+                                                       toConsole = *saveFD;
+                                                       *saveFD = NULL;
+                                                       fprintf(stderr, 
"Starting '%s' failed\n", pager);
+                                               }
+                                       }
+#endif
                                }
                        }
-#endif
                }
        }
 }
@@ -3126,10 +3131,21 @@ main(int argc, char **argv)
         * causes the output to be converted (we could set it to
         * ".OCP" if we knew for sure that we were running in a cmd
         * window) */
-       setlocale(LC_CTYPE, "");
+       if(setlocale(LC_CTYPE, "") == NULL) {
+               fprintf(stderr, "error: could not set locale\n");
+               exit(2);
+       }
 #endif
        toConsole = stdout_stream = file_wastream(stdout, "stdout");
        stderr_stream = file_wastream(stderr, "stderr");
+       if(!stdout_stream || !stderr_stream) {
+               if(stdout_stream)
+                       close_stream(stdout_stream);
+               if(stderr_stream)
+                       close_stream(stderr_stream);
+               fprintf(stderr, "error: could not open an output stream\n");
+               exit(2);
+       }
 
        /* parse config file first, command line options override */
        parse_dotmonetdb(&user, &passwd, &dbname, &language, &save_history, 
&output, &pagewidth);
@@ -3540,6 +3556,13 @@ main(int argc, char **argv)
 
        if (!has_fileargs && command == NULL) {
                stream *s = file_rastream(stdin, "<stdin>");
+               if(!s) {
+                       mapi_destroy(mid);
+                       mnstr_destroy(stdout_stream);
+                       mnstr_destroy(stderr_stream);
+                       fprintf(stderr,"Failed to open stream for stdin\n");
+                       exit(2);
+               }
                c = doFile(mid, s, useinserts, interactive, save_history);
        }
 
diff --git a/common/stream/stream.c b/common/stream/stream.c
--- a/common/stream/stream.c
+++ b/common/stream/stream.c
@@ -1456,7 +1456,6 @@ stream_xzread(stream *restrict s, void *
                        xz->todo = xz->strm.avail_in;
                        if (xz->todo > 0)
                                memmove(xz->buf, xz->strm.next_in, xz->todo);
-                       outbuf[origsize] = 0;   /* add EOS */
                        ressize = origsize;
                        break;
                }
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -1301,10 +1301,14 @@ BBPinit(void)
        FILE *fp = NULL;
        struct stat st;
        unsigned bbpversion;
-       str bbpdirstr = GDKfilepath(0, BATDIR, "BBP", "dir");
-       str backupbbpdirstr = GDKfilepath(0, BAKDIR, "BBP", "dir");
+       str bbpdirstr, backupbbpdirstr;
        int i;
 
+       if(!(bbpdirstr = GDKfilepath(0, BATDIR, "BBP", "dir")))
+               GDKfatal("BBPinit: GDKmalloc failed\n");
+       if(!(backupbbpdirstr = GDKfilepath(0, BAKDIR, "BBP", "dir")))
+               GDKfatal("BBPinit: GDKmalloc failed\n");
+
 #ifdef NEED_MT_LOCK_INIT
        MT_lock_init(&GDKunloadLock, "GDKunloadLock");
        ATOMIC_INIT(BBPsizeLock);
@@ -2980,11 +2984,16 @@ BBPprepare(bool subcommit)
 {
        bool start_subcommit;
        int set = 1 + subcommit;
-       str bakdirpath = GDKfilepath(0, NULL, BAKDIR, NULL);
-       str subdirpath = GDKfilepath(0, NULL, SUBDIR, NULL);
-
+       str bakdirpath, subdirpath;
        gdk_return ret = GDK_SUCCEED;
 
+       if(!(bakdirpath = GDKfilepath(0, NULL, BAKDIR, NULL)))
+               return GDK_FAIL;
+       if(!(subdirpath = GDKfilepath(0, NULL, SUBDIR, NULL))) {
+               GDKfree(bakdirpath);
+               return GDK_FAIL;
+       }
+
        /* tmLock is only used here, helds usually very shortly just
         * to protect the file counters */
        MT_lock_set(&GDKtmLock);
@@ -3122,7 +3131,8 @@ BBPbackup(BAT *b, bool subcommit)
                return GDK_SUCCEED;
        }
        /* determine location dir and physical suffix */
-       srcdir = GDKfilepath(NOFARM, BATDIR, s, NULL);
+       if (!(srcdir = GDKfilepath(NOFARM, BATDIR, s, NULL)))
+               goto fail;
        s = strrchr(srcdir, DIR_SEP);
        if (!s)
                goto fail;
@@ -3142,8 +3152,9 @@ BBPbackup(BAT *b, bool subcommit)
                goto fail;
        GDKfree(srcdir);
        return GDK_SUCCEED;
-  fail:
-       GDKfree(srcdir);
+fail:
+       if(srcdir)
+               GDKfree(srcdir);
        return GDK_FAIL;
 }
 
@@ -3164,9 +3175,14 @@ BBPsync(int cnt, bat *subcommit)
        gdk_return ret = GDK_SUCCEED;
        bool bbpdirty = false;
        int t0 = 0, t1 = 0;
-
-       str bakdir = GDKfilepath(0, NULL, subcommit ? SUBDIR : BAKDIR, NULL);
-       str deldir = GDKfilepath(0, NULL, DELDIR, NULL);
+       str bakdir, deldir;
+
+       if(!(bakdir = GDKfilepath(0, NULL, subcommit ? SUBDIR : BAKDIR, NULL)))
+               return GDK_FAIL;
+       if(!(deldir = GDKfilepath(0, NULL, DELDIR, NULL))) {
+               GDKfree(bakdir);
+               return GDK_FAIL;
+       }
 
        PERFDEBUG t0 = t1 = GDKms();
 
@@ -3299,7 +3315,10 @@ force_move(int farmid, const char *srcdi
 
                strncpy(srcpath, name, len);
                srcpath[len] = '\0';
-               dstpath = GDKfilepath(farmid, dstdir, srcpath, NULL);
+               if(!(dstpath = GDKfilepath(farmid, dstdir, srcpath, NULL))) {
+                       GDKsyserror("force_move: malloc fail\n");
+                       return GDK_FAIL;
+               }
 
                /* step 1: remove the X.new file that is going to be
                 * overridden by X */
@@ -3314,7 +3333,10 @@ force_move(int farmid, const char *srcdi
 
                /* step 2: now remove the .kill file. This one is
                 * crucial, otherwise we'll never finish recovering */
-               killfile = GDKfilepath(farmid, srcdir, name, NULL);
+               if(!(killfile = GDKfilepath(farmid, srcdir, name, NULL))) {
+                       GDKsyserror("force_move: malloc fail\n");
+                       return GDK_FAIL;
+               }
                if (remove(killfile) != 0) {
                        ret = GDK_FAIL;
                        GDKsyserror("force_move: remove(%s)\n", killfile);
@@ -3330,8 +3352,12 @@ force_move(int farmid, const char *srcdi
 
                /* two legal possible causes: file exists or dir
                 * doesn't exist */
-               dstpath = GDKfilepath(farmid, dstdir, name, NULL);
-               srcpath = GDKfilepath(farmid, srcdir, name, NULL);
+               if(!(dstpath = GDKfilepath(farmid, dstdir, name, NULL)))
+                       return GDK_FAIL;
+               if(!(srcpath = GDKfilepath(farmid, srcdir, name, NULL))) {
+                       GDKfree(dstpath);
+                       return GDK_FAIL;
+               }
                if (remove(dstpath) != 0)       /* clear destination */
                        ret = GDK_FAIL;
                IODEBUG fprintf(stderr, "#remove %s = %d\n", dstpath, (int) 
ret);
diff --git a/gdk/gdk_heap.c b/gdk/gdk_heap.c
--- a/gdk/gdk_heap.c
+++ b/gdk/gdk_heap.c
@@ -120,7 +120,10 @@ HEAPalloc(Heap *h, size_t nitems, size_t
                char *nme;
                struct stat st;
 
-               nme = GDKfilepath(h->farmid, BATDIR, h->filename, NULL);
+               if(!(nme = GDKfilepath(h->farmid, BATDIR, h->filename, NULL))) {
+                       GDKerror("HEAPalloc: malloc failure");
+                       return GDK_FAIL;
+               }
                if (stat(nme, &st) < 0) {
                        h->storage = STORE_MMAP;
                        h->base = HEAPcreatefile(NOFARM, &h->size, nme);
@@ -336,7 +339,8 @@ HEAPshrink(Heap *h, size_t size)
                        /* don't grow */
                        return GDK_SUCCEED;
                }
-               path = GDKfilepath(h->farmid, BATDIR, h->filename, NULL);
+               if(!(path = GDKfilepath(h->farmid, BATDIR, h->filename, NULL)))
+                       return GDK_FAIL;
                p = GDKmremap(path,
                              h->storage == STORE_PRIV ?
                                MMAP_COPY | MMAP_READ | MMAP_WRITE :
diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -1473,14 +1473,15 @@ static gdk_return
 logger_load(int debug, const char *fn, char filename[FILENAME_MAX], logger *lg)
 {
        int id = LOG_SID;
-       FILE *fp;
+       FILE *fp = NULL;
        char bak[FILENAME_MAX];
        str filenamestr = NULL;
        log_bid snapshots_bid = 0;
        bat catalog_bid, catalog_nme, dcatalog, bid;
        int farmid = BBPselectfarm(lg->dbfarm_role, 0, offheap);
 
-       filenamestr = GDKfilepath(farmid, lg->dir, LOGFILE, NULL);
+       if(!(filenamestr = GDKfilepath(farmid, lg->dir, LOGFILE, NULL)))
+               goto error;
        snprintf(filename, FILENAME_MAX, "%s", filenamestr);
        snprintf(bak, sizeof(bak), "%s.bak", filename);
        GDKfree(filenamestr);
diff --git a/gdk/gdk_system.c b/gdk/gdk_system.c
--- a/gdk/gdk_system.c
+++ b/gdk/gdk_system.c
@@ -446,13 +446,18 @@ find_posthread(pthread_t tid)
 #endif
 
 #ifdef HAVE_PTHREAD_SIGMASK
-static void
+static int
 MT_thread_sigmask(sigset_t * new_mask, sigset_t * orig_mask)
 {
-       (void) sigdelset(new_mask, SIGQUIT);
-       (void) sigdelset(new_mask, SIGALRM);    /* else sleep doesn't work */
-       (void) sigdelset(new_mask, SIGPROF);
-       (void) pthread_sigmask(SIG_SETMASK, new_mask, orig_mask);
+       if(sigdelset(new_mask, SIGQUIT))
+               return -1;
+       if(sigdelset(new_mask, SIGALRM))        /* else sleep doesn't work */
+               return -1;
+       if(sigdelset(new_mask, SIGPROF))
+               return -1;
+       if(pthread_sigmask(SIG_SETMASK, new_mask, orig_mask))
+               return -1;
+       return 0;
 }
 #endif
 
@@ -554,8 +559,10 @@ MT_create_thread(MT_Id *t, void (*f) (vo
 
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to