Skip to content

Commit 06d3661

Browse files
authored
Merge pull request #6961 from BOINC/dpa_shmem
client (Unix): abort job if shared-mem creation fails
2 parents 0516420 + a65ebb9 commit 06d3661

4 files changed

Lines changed: 14 additions & 10 deletions

File tree

client/app_start.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ int ACTIVE_TASK::start() {
996996
"ACTIVE_TASK::start(): can't create memory-mapped file: %s",
997997
boincerror(retval)
998998
);
999-
return retval;
999+
return ERR_MMAP;
10001000
}
10011001
} else {
10021002
// Use shmget() shared memory
@@ -1211,9 +1211,6 @@ int ACTIVE_TASK::resume_or_start(bool first_time) {
12111211
case PROCESS_UNINITIALIZED:
12121212
str = (first_time)?"Starting":"Restarting";
12131213
retval = start();
1214-
if ((retval == ERR_SHMGET) || (retval == ERR_SHMAT)) {
1215-
return retval;
1216-
}
12171214
if (retval) {
12181215
set_task_state(PROCESS_COULDNT_START, "resume_or_start1");
12191216
return retval;

lib/error_numbers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,11 @@
214214
#define ERR_NEED_HTTPS -238
215215
#define ERR_CHMOD -239
216216
#define ERR_STAT -240
217+
// or fstat()
217218
#define ERR_FCLOSE -241
218219
#define ERR_ACCT_REQUIRE_CONSENT -242
219220
#define ERR_INVALID_STATE -243
221+
#define ERR_MMAP -244
220222

221223
// PLEASE: add a text description of your error to
222224
// the text description function boincerror() in str_util.cpp.

lib/shmem.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,9 @@ int create_shmem_mmap(const char *path, size_t size, void** pp) {
302302

303303
// Return NULL pointer if create_shmem fails
304304
*pp = 0;
305-
if (size == 0) return ERR_SHMGET;
305+
if (size == 0) {
306+
return ERR_NULL;
307+
}
306308

307309
// NOTE: in principle it should be 0660, not 0666
308310
// (i.e. Apache should belong to the same group as the
@@ -313,22 +315,24 @@ int create_shmem_mmap(const char *path, size_t size, void** pp) {
313315
// and it's not a significant security issue.
314316
//
315317
fd = open(path, O_RDWR | O_CREAT, 0666);
316-
if (fd < 0) return ERR_SHMGET;
318+
if (fd < 0) {
319+
return ERR_OPEN;
320+
}
317321

318322
retval = fstat(fd, &sbuf);
319323
if (retval) {
320324
close(fd);
321-
return ERR_SHMGET;
325+
return ERR_STAT;
322326
}
323327
if (sbuf.st_size < (long)size) {
324328
// The following 2 lines extend the file and clear its new
325329
// area to all zeros because they write beyond the old EOF.
326330
// See the lseek man page for details.
327331
lseek(fd, size-1, SEEK_SET);
328332
if (1 != write(fd, "\0", 1)) {
329-
close(fd);
330-
return ERR_SHMGET;
331-
}
333+
close(fd);
334+
return ERR_WRITE;
335+
}
332336
}
333337

334338
*pp = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0);

lib/str_util.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ const char* boincerror(int which_error) {
624624
case ERR_STAT : return "stat() failed";
625625
case ERR_FCLOSE : return "fclose() failed";
626626
case ERR_INVALID_STATE: return "invalid state";
627+
case ERR_MMAP: return "mmap() failed";
627628
case HTTP_STATUS_NOT_FOUND: return "HTTP file not found";
628629
case HTTP_STATUS_PROXY_AUTH_REQ: return "HTTP proxy authentication failure";
629630
case HTTP_STATUS_RANGE_REQUEST_ERROR: return "HTTP range request error";

0 commit comments

Comments
 (0)