Skip to content

Commit eb512a5

Browse files
committed
Commit 775e220 introduced a regression: EEXIST isn't supposed to cause an exception to be thrown. Fix this.
1 parent 6b39c23 commit eb512a5

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

ext/common/Utils.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -355,26 +355,30 @@ setPassengerTempDir(const string &dir) {
355355
static void
356356
createNonWritableFifo(const string &filename) {
357357
int ret, e;
358+
bool ignoreChmodErrors = false;
358359

359360
do {
360361
ret = mkfifo(filename.c_str(), 0);
361362
} while (ret == -1 && errno == EINTR);
362363
if (ret == -1) {
363-
if (errno == EEXIST && geteuid() != 0) {
364-
// Don't try to change the permissions on the FIFO file;
365-
// it was likely created by root, but after lowering privilege
366-
// createPassengerTempDir() is called again, and this time
367-
// we won't be able to set permissions.
368-
return;
364+
if (errno == EEXIST) {
365+
/* The FIFO file was likely created by root, but after lowering
366+
* privilege createPassengerTempDir() is called again, and this
367+
* time we won't be able to set permissions. So in this case
368+
* we'll want to ignore any chmod errors.
369+
*/
370+
ignoreChmodErrors = geteuid() != 0;
371+
} else {
372+
e = errno;
373+
throw FileSystemException("Cannot create FIFO file " + filename,
374+
e, filename);
369375
}
370-
e = errno;
371-
throw FileSystemException("Cannot create FIFO file " + filename, e, filename);
372376
}
373377

374378
do {
375379
ret = chmod(filename.c_str(), 0);
376380
} while (ret == -1 && errno == EINTR);
377-
if (ret == -1) {
381+
if (ret == -1 && !ignoreChmodErrors) {
378382
e = errno;
379383
throw FileSystemException("Cannot set permissions on file " + filename, e, filename);
380384
}

0 commit comments

Comments
 (0)