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 469
 		return 1;
469 470
 	}
470 471
 	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
-	} 
472
+	if (stat(fifo, &filestat)==-1) { /* FIFO doesn't exist yet ... */
473
+		LOG(L_DBG, "DEBUG: open_fifo_server: FIFO stat failed: %s\n",
474
+			strerror(errno));
475
+		if ((mkfifo(fifo, fifo_mode)<0)) {
476
+			LOG(L_ERR, "ERROR: open_fifo_server; can't create FIFO: "
477
+					"%s (mode=%d)\n",
478
+					strerror(errno), fifo_mode);
479
+			return -1;
480
+		} 
481
+		DBG("DEBUG: FIFO created @ %s\n", fifo );
482
+		if ((chmod(fifo, fifo_mode)<0)) {
483
+			LOG(L_ERR, "ERROR: open_fifo_server; can't chmod FIFO: "
484
+					"%s (mode=%d)\n",
485
+					strerror(errno), fifo_mode);
486
+			return -1;
487
+		}
488
+	} else { /* file can be stat-ed, check if it is really a FIFO */
489
+		if (!(S_ISFIFO(filestat.st_mode))) {
490
+			LOG(L_ERR, "ERROR: open_fifo_server: "
491
+				"the file is not a FIFO: %s\n",
492
+				fifo );
493
+			return -1;
494
+		}
495
+	}
477 496
 	DBG("DEBUG: fifo %s opened, mode=%d\n", fifo, fifo_mode );
478 497
 	time(&up_since);
479 498
 	t=ctime(&up_since);