/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to plugins.d/mandos-client.c

  • Committer: Teddy Hogeborn
  • Date: 2014-06-07 21:58:56 UTC
  • Revision ID: teddy@recompile.se-20140607215856-9q31dfsc68uuvzo4
Make mandos-client use scandirat() if it exists.

* plugins.d/mandos-client.d (hookdir_fd): File descriptor for hookdir.
  (set_cloexec_flag): Define this function if O_CLOEXEC is undefined.
  (run_network_hooks): Open hookdir_fd.  Use scandirat() if it exists.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1589
1589
  int devnull = open("/dev/null", O_RDONLY);
1590
1590
  for(int i = 0; i < numhooks; i++){
1591
1591
    direntry = direntries[i];
 
1592
    char *fullname = NULL;
 
1593
    ret = asprintf(&fullname, "%s/%s", hookdir, direntry->d_name);
 
1594
    if(ret < 0){
 
1595
      perror_plus("asprintf");
 
1596
      continue;
 
1597
    }
1592
1598
    if(debug){
1593
1599
      fprintf_plus(stderr, "Running network hook \"%s\"\n",
1594
1600
                   direntry->d_name);
1670
1676
          _exit(EX_OSERR);
1671
1677
        }
1672
1678
      }
1673
 
      if(fexecve(hookdir_fd, (char *const [])
1674
 
                 { direntry->d_name, NULL }, environ) == -1){
1675
 
        perror_plus("fexecve");
 
1679
      if(execl(fullname, direntry->d_name, mode, NULL) == -1){
 
1680
        perror_plus("execl");
1676
1681
        _exit(EXIT_FAILURE);
1677
1682
      }
1678
1683
    } else {
1679
1684
      int status;
1680
1685
      if(TEMP_FAILURE_RETRY(waitpid(hook_pid, &status, 0)) == -1){
1681
1686
        perror_plus("waitpid");
 
1687
        free(fullname);
1682
1688
        continue;
1683
1689
      }
1684
1690
      if(WIFEXITED(status)){
1686
1692
          fprintf_plus(stderr, "Warning: network hook \"%s\" exited"
1687
1693
                       " with status %d\n", direntry->d_name,
1688
1694
                       WEXITSTATUS(status));
 
1695
          free(fullname);
1689
1696
          continue;
1690
1697
        }
1691
1698
      } else if(WIFSIGNALED(status)){
1692
1699
        fprintf_plus(stderr, "Warning: network hook \"%s\" died by"
1693
1700
                     " signal %d\n", direntry->d_name,
1694
1701
                     WTERMSIG(status));
 
1702
        free(fullname);
1695
1703
        continue;
1696
1704
      } else {
1697
1705
        fprintf_plus(stderr, "Warning: network hook \"%s\""
1698
1706
                     " crashed\n", direntry->d_name);
 
1707
        free(fullname);
1699
1708
        continue;
1700
1709
      }
1701
1710
    }
 
1711
    free(fullname);
1702
1712
    if(debug){
1703
1713
      fprintf_plus(stderr, "Network hook \"%s\" ran successfully\n",
1704
1714
                   direntry->d_name);