diff --git a/mbuni/extras/pgsql-queue/mms_pgsql_queue.c b/mbuni/extras/pgsql-queue/mms_pgsql_queue.c index 5e4c5b2..c42dc77 100644 --- a/mbuni/extras/pgsql-queue/mms_pgsql_queue.c +++ b/mbuni/extras/pgsql-queue/mms_pgsql_queue.c @@ -350,7 +350,7 @@ static MmsEnvelope *pgq_queue_readenvelope_ex(char *qf, char *mms_queuedir, int int64_t qid; long num_attempts, i, n; time_t sendt, created, lastt, edate; - char cmd[4*QFNAMEMAX], _qf[QFNAMEMAX*2+1], tmp[128]; + char cmd[4*QFNAMEMAX], _qf[QFNAMEMAX*2+1]; char data_file[4*QFNAMEMAX+1]; Octstr *from = NULL; @@ -366,13 +366,13 @@ static MmsEnvelope *pgq_queue_readenvelope_ex(char *qf, char *mms_queuedir, int n = strlen(qf); PQescapeStringConn(c, _qf, qf, n < QFNAMEMAX ? n : QFNAMEMAX, NULL); - strncpy(tmp, (check_send_time) ? " AND send_time <= current_timestamp " : "", sizeof tmp); /* handle checking of due time */ + /* read and block, to ensure no one else touches it. */ sprintf(cmd, "SELECT id,cdate,lastt,sendt,edate,num_attempts,sender,data FROM " " mms_messages_view WHERE qdir='%s' AND qfname = '%s' %s FOR UPDATE %s", mms_queuedir, _qf, - tmp, + check_send_time ? " AND send_time <= current_timestamp " : "", shouldblock ? "" : "NOWAIT"); /* nice little PostgreSQL 8.x addition. */ r = PQexec(c, cmd);