shared/misc.h
7b304dee
 /*
206dbaef
  *  Copyright (C) 2013-2020 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
52cddcbc
  *  Copyright (C) 2007-2013 Sourcefire, Inc.
086eab5c
  *
  *  Authors: Tomasz Kojm
7b304dee
  *
  *  This program is free software; you can redistribute it and/or modify
bb34cb31
  *  it under the terms of the GNU General Public License version 2 as
  *  published by the Free Software Foundation.
7b304dee
  *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
48b7b4a7
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  *  MA 02110-1301, USA.
7b304dee
  */
 
 #ifndef __MISC_H
 #define __MISC_H
4cd80898
 #ifndef _WIN32
c23331be
 #include <sys/types.h>
7a997ac9
 #include <netdb.h>
 #include <netinet/in.h>
4cd80898
 #endif
ec62e185
 #include <stdbool.h>
 
8efbf4a0
 #include "platform.h"
40331c57
 #include "optparser.h"
53725d8c
 /* Maximum filenames under various systems - njh */
72fd33c8
 #ifndef NAME_MAX  /* e.g. Linux */
 #ifdef MAXNAMELEN /* e.g. Solaris */
 #define NAME_MAX MAXNAMELEN
 #else
 #ifdef FILENAME_MAX /* e.g. SCO */
 #define NAME_MAX FILENAME_MAX
 #endif
 #endif
53725d8c
 #endif
 
b68375fd
 #ifdef HAVE_SYSTEMD
72fd33c8
 #include <systemd/sd-daemon.h>
b68375fd
 #else
72fd33c8
 #define sd_listen_fds(u) 0
 #define SD_LISTEN_FDS_START 3
 #define sd_is_socket(f, a, s, l) 1
b68375fd
 #endif
 
bfd89d7c
 #include <limits.h>
 
 #ifndef PATH_MAX
 #define PATH_MAX 1024
 #endif
 
0d78af13
 #ifndef ADDR_LEN
 #define ADDR_LEN 13
 #endif
 
98ce643b
 char *freshdbdir(void);
0aa3ba06
 void print_version(const char *dbdir);
bca0b679
 int check_flevel(void);
c2b6681b
 const char *filelist(const struct optstruct *opts, int *err);
63abd169
 int filecopy(const char *src, const char *dest);
5b168b50
 
b88a29d6
 #ifndef _WIN32
5b168b50
 /*Returns 0 on success (only the child process returns.*/
587d344b
 int daemonize(void);
5b168b50
 
 /*closes stdin, stdout, stderr.  This is called by daemonize, but not
  * daemonize_all_return.  Users of daemonize_all_return should call this
  * when initialization is complete.*/
b88a29d6
 int close_std_descriptors();
 
5b168b50
 /*Returns the return value of fork.  All processes return */
 int daemonize_all_return(void);
b88a29d6
 
5b168b50
 /*Parent waits for a SIGINT or the child process to exit.  If
  * it receives a SIGINT, it exits with exit code 0.  If the child
ec62e185
  * exits (error), it exits with the child process's exit code.
  *
  * @param user If user is supplied and this function is being called
  * as root, daemonize_parent_wait will change the parent process
  * to user before calling wait so that the child process can signal
  * the parent when it is time to exit.  The child process will still
  * return as root.
  *
  * @param log_file If user AND log_file are both supplied and this
  * function is being called as root, the ownership of log_file will
  * be changed to user.
  */
 int daemonize_parent_wait(const char * const user, const char * const log_file);
b88a29d6
 
5b168b50
 /*Sends a SIGINT to the parent process.  It also closes stdin, stdout, 
  * and stderr.*/
 void daemonize_signal_parent(pid_t parentPid);
ec62e185
 
 int drop_privileges( const char * const user, const char * const log_file);
 #endif /* _WIN32 */
5b168b50
 
add738d2
 const char *get_version(void);
5cd3f734
 int match_regex(const char *filename, const char *pattern);
11195c0b
 int cli_is_abspath(const char *path);
4dccd075
 unsigned int countlines(const char *filename);
11195c0b
 
7b304dee
 #endif