Browse code

fifo_server changes: - permissions are only set during FIFO creation (no more reset) - permission are set using chmod now (overrides umask) - SER is more talkative during attempts to create FIFO

Jiri Kuthan authored on 27/11/2002 20:45:54
Showing 1 changed files
... ...
@@ -457,6 +457,7 @@ consume:
457 457
 int open_fifo_server()
458 458
 {
459 459
 	char *t;
460
+	struct stat filestat;
460 461
 
461 462
 	if (fifo==NULL) {
462 463
 		DBG("TM: open_uac_fifo: no fifo will be opened\n");
... ...
@@ -468,12 +469,30 @@ int open_fifo_server()
468 468
 		return 1;
469 469
 	}
470 470
 	DBG("TM: open_uac_fifo: opening fifo...\n");
471
-	if ((mkfifo(fifo, fifo_mode)<0) && (errno!=EEXIST)) {
472
-		LOG(L_ERR, "ERROR: open_fifo_server; can't create FIFO: "
473
-			"%s (mode=%d)\n",
474
-			strerror(errno), fifo_mode);
475
-		return -1;
476
-	} 
471
+	if (stat(fifo, &filestat)==-1) { /* FIFO doesn't exist yet ... */
472
+		LOG(L_DBG, "DEBUG: open_fifo_server: FIFO stat failed: %s\n",
473
+			strerror(errno));
474
+		if ((mkfifo(fifo, fifo_mode)<0)) {
475
+			LOG(L_ERR, "ERROR: open_fifo_server; can't create FIFO: "
476
+					"%s (mode=%d)\n",
477
+					strerror(errno), fifo_mode);
478
+			return -1;
479
+		} 
480
+		DBG("DEBUG: FIFO created @ %s\n", fifo );
481
+		if ((chmod(fifo, fifo_mode)<0)) {
482
+			LOG(L_ERR, "ERROR: open_fifo_server; can't chmod FIFO: "
483
+					"%s (mode=%d)\n",
484
+					strerror(errno), fifo_mode);
485
+			return -1;
486
+		}
487
+	} else { /* file can be stat-ed, check if it is really a FIFO */
488
+		if (!(S_ISFIFO(filestat.st_mode))) {
489
+			LOG(L_ERR, "ERROR: open_fifo_server: "
490
+				"the file is not a FIFO: %s\n",
491
+				fifo );
492
+			return -1;
493
+		}
494
+	}
477 495
 	DBG("DEBUG: fifo %s opened, mode=%d\n", fifo, fifo_mode );
478 496
 	time(&up_since);
479 497
 	t=ctime(&up_since);