| File: | fork-detect.c |
| Warning: | line 53, column 16 This statement is never executed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /*-*- Mode: C; c-basic-offset: 8 -*-*/ |
| 2 | |
| 3 | /*** |
| 4 | This file is part of libkanberra. |
| 5 | |
| 6 | Copyright 2009 Lennart Poettering |
| 7 | |
| 8 | libkanberra is free software; you can redistribute it and/or modify |
| 9 | it under the terms of the GNU Lesser General Public License as |
| 10 | published by the Free Software Foundation, either version 2.1 of the |
| 11 | License, or (at your option) any later version. |
| 12 | |
| 13 | libkanberra is distributed in the hope that it will be useful, but |
| 14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | Lesser General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU Lesser General Public |
| 19 | License along with libkanberra. If not, see |
| 20 | <http://www.gnu.org/licenses/>. |
| 21 | ***/ |
| 22 | |
| 23 | #ifdef HAVE_CONFIG_H1 |
| 24 | #include <config.h> |
| 25 | #endif |
| 26 | |
| 27 | #include <unistd.h> |
| 28 | #include <sys/types.h> |
| 29 | |
| 30 | #include "fork-detect.h" |
| 31 | |
| 32 | int ka_detect_fork(void) { |
| 33 | static volatile pid_t pid = (pid_t) -1; |
| 34 | pid_t v, we; |
| 35 | |
| 36 | /* Some really stupid applications (Hey, vim, that means you!) |
| 37 | * love to fork after initializing ctk/libkanberra. This is really |
| 38 | * bad style. We however have to deal with this cleanly, so we try |
| 39 | * to detect the forks making sure all our calls fail cleanly |
| 40 | * after the fork. */ |
| 41 | |
| 42 | /* Ideally we'd use atomic operations here, but we don't have them |
| 43 | * and this is not exactly crucial, so we don't care */ |
| 44 | |
| 45 | v = pid; |
| 46 | we = getpid(); |
| 47 | |
| 48 | if (v == we || v == (pid_t) -1) { |
| 49 | pid = we; |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | return 1; |
This statement is never executed | |
| 54 | } |