"Fossies" - the Fresh Open Source Software Archive

Member "feh-3.4.1/src/signals.c" (29 May 2020, 3114 Bytes) of package /linux/privat/feh-3.4.1.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "signals.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 3.4_vs_3.4.1.

    1 /* signals.c
    2 
    3 Copyright (C) 2010-2020 by Daniel Friesel
    4 
    5 Permission is hereby granted, free of charge, to any person obtaining a copy
    6 of this software and associated documentation files (the "Software"), to
    7 deal in the Software without restriction, including without limitation the
    8 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
    9 sell copies of the Software, and to permit persons to whom the Software is
   10 furnished to do so, subject to the following conditions:
   11 
   12 The above copyright notice and this permission notice shall be included in
   13 all copies of the Software and its documentation and acknowledgment shall be
   14 given in the documentation and software packages that this Software was
   15 used.
   16 
   17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
   20 THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
   21 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
   22 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   23 
   24 */
   25 
   26 #include "feh.h"
   27 #include "filelist.h"
   28 #include "winwidget.h"
   29 #include "options.h"
   30 
   31 void feh_handle_signal(int);
   32 volatile int sig_exit = 0;
   33 
   34 void setup_signal_handlers()
   35 {
   36     struct sigaction feh_sh;
   37     sigset_t feh_ss;
   38     if (
   39         (sigemptyset(&feh_ss) == -1) ||
   40         (sigaddset(&feh_ss, SIGUSR1) == -1) ||
   41         (sigaddset(&feh_ss, SIGUSR2) == -1) ||
   42         (sigaddset(&feh_ss, SIGALRM) == -1) ||
   43         (sigaddset(&feh_ss, SIGTERM) == -1) ||
   44         (sigaddset(&feh_ss, SIGQUIT) == -1) ||
   45         (sigaddset(&feh_ss, SIGINT) == -1) ||
   46         (sigaddset(&feh_ss, SIGTTIN) == -1))
   47     {
   48         weprintf("Failed to set up signal masks");
   49         return;
   50     }
   51 
   52     feh_sh.sa_handler = feh_handle_signal;
   53     feh_sh.sa_mask    = feh_ss;
   54     feh_sh.sa_flags   = 0;
   55 
   56     if (
   57         (sigaction(SIGUSR1, &feh_sh, NULL) == -1) ||
   58         (sigaction(SIGUSR2, &feh_sh, NULL) == -1) ||
   59         (sigaction(SIGALRM, &feh_sh, NULL) == -1) ||
   60         (sigaction(SIGTERM, &feh_sh, NULL) == -1) ||
   61         (sigaction(SIGQUIT, &feh_sh, NULL) == -1) ||
   62         (sigaction(SIGINT, &feh_sh, NULL) == -1) ||
   63         (sigaction(SIGTTIN, &feh_sh, NULL) == -1))
   64     {
   65         weprintf("Failed to set up signal handler");
   66         return;
   67     }
   68 
   69     return;
   70 }
   71 
   72 void feh_handle_signal(int signo)
   73 {
   74     winwidget winwid;
   75     int i;
   76 
   77     switch (signo) {
   78         case SIGALRM:
   79             if (childpid)
   80                 killpg(childpid, SIGINT);
   81             return;
   82         case SIGTTIN:
   83             // we were probably backgrounded while we were running
   84             control_via_stdin = 0;
   85             return;
   86         case SIGINT:
   87         case SIGTERM:
   88         case SIGQUIT:
   89             if (childpid)
   90                 killpg(childpid, SIGINT);
   91             sig_exit = 128 + signo;
   92             return;
   93     }
   94 
   95     winwid = winwidget_get_first_window_of_type(WIN_TYPE_SLIDESHOW);
   96 
   97     if (winwid) {
   98         if (filelist_len > 1) {
   99             if (signo == SIGUSR1)
  100                 slideshow_change_image(winwid, SLIDE_NEXT, 1);
  101             else if (signo == SIGUSR2)
  102                 slideshow_change_image(winwid, SLIDE_PREV, 1);
  103         } else {
  104             feh_reload_image(winwid, 0, 0);
  105         }
  106     } else if (opt.multiwindow) {
  107         for (i = window_num - 1; i >= 0; i--)
  108             feh_reload_image(windows[i], 0, 0);
  109     }
  110 
  111     return;
  112 }