Changeset: 2ec54a40d25e for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2ec54a40d25e
Modified Files:
sql/src/backends/monet5/merovingian/daemon/client.c
sql/src/backends/monet5/merovingian/daemon/controlrunner.c
sql/src/backends/monet5/merovingian/daemon/merovingian.c
sql/src/backends/monet5/merovingian/daemon/proxy.c
Branch: default
Log Message:
pthread_create returns an error number, 0 on success
Fix the usage of pthread_create. It returns the actual error number,
which is never < 0 under Linux. Further the manpage states that it was
only successful when it returns 0.
diffs (207 lines):
diff -r 92bb5c749bd0 -r 2ec54a40d25e
sql/src/backends/monet5/merovingian/daemon/client.c
--- a/sql/src/backends/monet5/merovingian/daemon/client.c Tue Jan 04
15:16:55 2011 +0100
+++ b/sql/src/backends/monet5/merovingian/daemon/client.c Tue Jan 04
15:29:59 2011 +0100
@@ -241,6 +241,7 @@
}
if (w == NULL) {
char *err;
+ int ret;
w = malloc(sizeof(mplist));
w->next = mero_multiplex_funnel;
if ((err = multiplexInit(&w->mpf, database)) != NULL) {
@@ -253,17 +254,18 @@
return(err);
}
mero_multiplex_funnel = w;
- if (pthread_create(&w->mpf->tid,
+ if ((ret = pthread_create(&w->mpf->tid,
NULL, (void *(*)(void
*))multiplexThread,
- (void *)w->mpf) < 0)
+ (void *)w->mpf)) != 0)
{
mnstr_printf(fout, "!merovingian: internal
failure while "
- "creating multiplex-funnel:
unable to start thread\n");
+ "creating multiplex-funnel:
unable to start thread: %s\n",
+ strerror(ret));
mnstr_flush(fout);
close_stream(fout);
close_stream(fdin);
- return(newErr("starting thread for
multiplex-funnel %s failed",
- database));
+ return(newErr("starting thread for
multiplex-funnel %s failed: %s",
+ database,
strerror(ret)));
}
}
multiplexAddClient(w->mpf, sock, fout, fdin, host);
diff -r 92bb5c749bd0 -r 2ec54a40d25e
sql/src/backends/monet5/merovingian/daemon/controlrunner.c
--- a/sql/src/backends/monet5/merovingian/daemon/controlrunner.c Tue Jan
04 15:16:55 2011 +0100
+++ b/sql/src/backends/monet5/merovingian/daemon/controlrunner.c Tue Jan
04 15:29:59 2011 +0100
@@ -271,14 +271,15 @@
send(msgsock, buf2, len, 0);
} else if (strcmp(q, "peer") == 0) {
pthread_t ptid; /* FIXME: register global */
+ int ret;
len = snprintf(buf2, sizeof(buf2), "OK\n");
send(msgsock, buf2, len, 0);
/* start a separate thread to handle the
peering */
- if (pthread_create(&ptid, NULL,
+ if ((ret = pthread_create(&ptid, NULL,
(void *(*)(void
*))peeringServerThread,
- (void *)&msgsock) < 0)
+ (void *)&msgsock)) != 0)
{
- /* FIXME: FAIL */
+ /* FIXME: FAIL strerror(ret) */
}
} else {
Mfprintf(_mero_ctlout, "%s: invalid mode "
diff -r 92bb5c749bd0 -r 2ec54a40d25e
sql/src/backends/monet5/merovingian/daemon/merovingian.c
--- a/sql/src/backends/monet5/merovingian/daemon/merovingian.c Tue Jan 04
15:16:55 2011 +0100
+++ b/sql/src/backends/monet5/merovingian/daemon/merovingian.c Tue Jan 04
15:29:59 2011 +0100
@@ -405,6 +405,7 @@
struct stat sb;
FILE *oerr = NULL;
pthread_mutexattr_t mta;
+ int thret;
confkeyval ckv[] = {
{"prefix", GDKstrdup(MONETDB5_PREFIX), STR},
{"gdk_dbfarm", NULL, STR},
@@ -834,8 +835,9 @@
pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&_mero_topdp_lock, &mta);
- if (pthread_create(&tid, NULL, (void *(*)(void *))logListener, (void
*)NULL) < 0) {
- Mfprintf(oerr, "%s: unable to create logthread, exiting\n",
argv[0]);
+ if ((thret = pthread_create(&tid, NULL, (void *(*)(void *))logListener,
(void *)NULL)) != 0) {
+ Mfprintf(oerr, "%s: FATAL: unable to create logthread: %s\n",
+ argv[0], strerror(thret));
MERO_EXIT(1);
}
@@ -847,7 +849,8 @@
sigaction(SIGQUIT, &sa, NULL) == -1 ||
sigaction(SIGTERM, &sa, NULL) == -1)
{
- Mfprintf(oerr, "%s: unable to create signal handlers\n",
argv[0]);
+ Mfprintf(oerr, "%s: FATAL: unable to create signal handlers:
%s\n",
+ argv[0], strerror(errno));
MERO_EXIT(1);
}
@@ -855,7 +858,8 @@
sa.sa_flags = 0;
sa.sa_handler = huphandler;
if (sigaction(SIGHUP, &sa, NULL) == -1) {
- Mfprintf(oerr, "%s: unable to create signal handlers\n",
argv[0]);
+ Mfprintf(oerr, "%s: FATAL: unable to create signal handlers:
%s\n",
+ argv[0], strerror(errno));
MERO_EXIT(1);
}
@@ -863,7 +867,8 @@
sa.sa_flags = 0;
sa.sa_handler = SIG_IGN;
if (sigaction(SIGPIPE, &sa, NULL) == -1) {
- Mfprintf(oerr, "%s: unable to create signal handlers\n",
argv[0]);
+ Mfprintf(oerr, "%s: FATAL: unable to create signal handlers:
%s\n",
+ argv[0], strerror(errno));
MERO_EXIT(1);
}
@@ -871,7 +876,8 @@
sigemptyset(&sa.sa_mask);
sa.sa_sigaction = childhandler;
if (sigaction(SIGCHLD, &sa, NULL) == -1) {
- Mfprintf(oerr, "%s: unable to create signal handlers\n",
argv[0]);
+ Mfprintf(oerr, "%s: FATAL: unable to create signal handlers:
%s\n",
+ argv[0], strerror(errno));
MERO_EXIT(1);
}
@@ -929,18 +935,21 @@
/* handle control commands */
csocks[0] = unsock;
csocks[1] = csock;
- if (pthread_create(&ctid, NULL, (void *(*)(void
*))controlRunner,
- (void *)&csocks) < 0)
+ if ((thret = pthread_create(&ctid, NULL,
+ (void *(*)(void
*))controlRunner,
+ (void *)&csocks)) != 0)
{
- Mfprintf(stderr, "unable to create control command
thread\n");
+ Mfprintf(stderr, "unable to create control command
thread: %s\n",
+ strerror(thret));
ctid = 0;
}
/* start neighbour discovery and notification thread */
- if (usock >= 0 && pthread_create(&dtid, NULL,
- (void *(*)(void *))discoveryRunner,
(void *)&usock) < 0)
+ if (usock >= 0 && (thret = pthread_create(&dtid, NULL,
+ (void *(*)(void *))discoveryRunner,
(void *)&usock)) != 0)
{
- Mfprintf(stderr, "unable to start neighbour discovery
thread\n");
+ Mfprintf(stderr, "unable to start neighbour discovery
thread: %s\n",
+ strerror(thret));
dtid = 0;
}
@@ -994,11 +1003,12 @@
}
tlw->next = NULL;
- if (pthread_create(&(tlw->tid), NULL,
- (void *(*)(void
*))terminateProcess, (void *)t) < 0)
+ if ((thret = pthread_create(&(tlw->tid), NULL,
+ (void *(*)(void
*))terminateProcess, (void *)t)) != 0)
{
Mfprintf(stderr, "%s: unable to create thread
to terminate "
- "database '%s'\n", argv[0],
d->dbname);
+ "database '%s': %s\n",
+ argv[0], d->dbname,
strerror(thret));
tlw->tid = 0;
}
diff -r 92bb5c749bd0 -r 2ec54a40d25e
sql/src/backends/monet5/merovingian/daemon/proxy.c
--- a/sql/src/backends/monet5/merovingian/daemon/proxy.c Tue Jan 04
15:16:55 2011 +0100
+++ b/sql/src/backends/monet5/merovingian/daemon/proxy.c Tue Jan 04
15:29:59 2011 +0100
@@ -112,6 +112,7 @@
merovingian_proxy *pctos, *pstoc;
pthread_t ptid;
pthread_attr_t detachattr;
+ int thret;
/* quick 'n' dirty parsing */
if (strncmp(url, "mapi:monetdb://", sizeof("mapi:monetdb://") - 1) ==
0) {
@@ -241,12 +242,12 @@
pstoc->name = NULL; /* we want only one log-message on disconnect */
pstoc->co_thr = 0;
- if (pthread_create(&ptid, NULL,
- (void *(*)(void *))proxyThread, (void *)pstoc)
< 0)
+ if ((thret = pthread_create(&ptid, NULL,
+ (void *(*)(void *))proxyThread, (void *)pstoc))
!= 0)
{
close_stream(sfout);
close_stream(sfdin);
- return(newErr("failed to create proxy thread"));
+ return(newErr("failed to create proxy thread: %s",
strerror(thret)));
}
pctos = GDKmalloc(sizeof(merovingian_proxy));
@@ -259,12 +260,12 @@
pthread_attr_init(&detachattr);
pthread_attr_setdetachstate(&detachattr, PTHREAD_CREATE_DETACHED);
- if (pthread_create(&ptid, &detachattr,
- (void *(*)(void *))proxyThread, (void *)pctos)
< 0)
+ if ((thret = pthread_create(&ptid, &detachattr,
+ (void *(*)(void *))proxyThread, (void *)pctos))
!= 0)
{
close_stream(sfout);
close_stream(sfdin);
- return(newErr("failed to create proxy thread"));
+ return(newErr("failed to create proxy thread: %s",
strerror(thret)));
}
return(NO_ERR);
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list