aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortenox <as@tenoware.com>2016-08-18 00:27:11 -0700
committertenox <as@tenoware.com>2016-08-18 00:27:11 -0700
commit374af96b209b39ec5578e5fe8caffc655acf8ad1 (patch)
tree5295f3c0c0e7230dc224889a574b22b054eee450
parentd104daea0969f5b3c9b55c769193da6d8ea99de1 (diff)
downloadwfm-374af96b209b39ec5578e5fe8caffc655acf8ad1.tar.gz
small fixes for SHM and upload status
-rw-r--r--cgic.c17
-rw-r--r--wfm.c14
2 files changed, 15 insertions, 16 deletions
diff --git a/cgic.c b/cgic.c
index 3991de2..0c7c2c3 100644
--- a/cgic.c
+++ b/cgic.c
@@ -69,9 +69,9 @@ char *cgiAccept;
char *cgiUserAgent;
char *cgiReferrer;
-char *shm_addr='\0';
-int shm_key=0;
-int shm_id=0;
+char *shm_addr=NULL;
+int shm_key=-1;
+int shm_id=-1;
#define SHM_SIZE 16
@@ -129,7 +129,7 @@ static int cgiStrBeginsNc(char *s1, char *s2);
/* Dirty little hack to get file upload progress - Part 4: SHM Cleanup */
void shmcleanup(void) {
- if(shm_id)
+ if(shm_id>=0)
shmctl(shm_id, IPC_RMID, NULL);
}
@@ -537,12 +537,11 @@ static cgiParseResultType cgiParsePostMultipartInput() {
}
outf = fopen(tfileName, "w+b");
/* Dirty little hack to get file upload progress - Part 1: Initialize */
- if (cgiFormInteger("upload_id", &shm_key, 0) == cgiFormSuccess && shm_key) {
- if ((shm_id = shmget(shm_key, 16, IPC_CREAT | 0666)) > 0) {
+ if (cgiFormInteger("upload_id", &shm_key, -1) == cgiFormSuccess && shm_key) {
+ if ((shm_id = shmget(shm_key, 16, IPC_CREAT | 0666)) >= 0) {
for(sig=1; sig<=31; sig++)
signal(sig, (void*)shmcleanup);
- if ((shm_addr = shmat(shm_id, NULL, 0)) > 0)
- *shm_addr='\0';
+ shm_addr = shmat(shm_id, NULL, 0);
}
}
} else {
@@ -553,7 +552,7 @@ static cgiParseResultType cgiParsePostMultipartInput() {
/* Dirty little hack to get file upload progress - Part 2: Clean up */
if(shm_addr)
shmdt(shm_addr);
- if(shm_id)
+ if(shm_id>=0)
shmctl(shm_id, IPC_RMID, NULL);
if (result != cgiParseSuccess) {
/* Lack of a boundary here is an error. */
diff --git a/wfm.c b/wfm.c
index 21a73ee..526278f 100644
--- a/wfm.c
+++ b/wfm.c
@@ -36,25 +36,25 @@ int icon(void) {
// Called by early action=upstat
//
void upload_status(void) {
- int shm_key=0;
- int shm_id=0;
- char *shm_addr='\0';
+ int shm_key=-1;
+ int shm_id=-1;
+ char *shm_addr=NULL;
if(cgiFormInteger("upload_id", &shm_key, 0) == cgiFormSuccess && shm_key) {
shm_id = shmget(shm_key, SHM_SIZE, 0666);
- if(shm_id > 0)
+ if(shm_id >= 0)
shm_addr = shmat(shm_id, NULL, 0);
}
fprintf(cgiOut, "Cache-Control: no-cache\r\n");
cgiHeaderContentType("text/plain");
- if(shm_id && shm_addr && *shm_addr)
+ if(shm_addr)
fprintf(cgiOut, "%s\r\n", shm_addr);
else
- fprintf(cgiOut, "-------\r\n");
+ fprintf(cgiOut, "-----\r\n");
- if (shm_id && shm_addr)
+ if (shm_addr)
shmdt(shm_addr);
exit(0);