2017-04-06 22:21:20 +00:00
|
|
|
/* util.h - Header for all utility functions
|
|
|
|
*/
|
|
|
|
|
2017-04-04 19:44:13 +00:00
|
|
|
#ifndef _UTILS_H_
|
|
|
|
#define _UTILS_H_
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2017-04-06 22:21:20 +00:00
|
|
|
#include <dirent.h>
|
2017-04-08 23:25:10 +00:00
|
|
|
#include <pthread.h>
|
2017-04-07 23:37:43 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
2017-04-14 19:23:09 +00:00
|
|
|
#include <sys/stat.h>
|
2017-04-04 19:44:13 +00:00
|
|
|
|
2017-04-07 23:37:43 +00:00
|
|
|
#include "vector.h"
|
2017-04-04 19:44:13 +00:00
|
|
|
|
2017-04-14 19:23:09 +00:00
|
|
|
#define UID_SHELL (get_shell_uid())
|
|
|
|
#define UID_ROOT 0
|
|
|
|
#define UID_SYSTEM (get_system_uid())
|
|
|
|
#define UID_RADIO (get_radio_uid())
|
|
|
|
|
2017-04-17 08:36:49 +00:00
|
|
|
extern int quit_signals[];
|
|
|
|
|
2017-04-04 19:44:13 +00:00
|
|
|
// xwrap.c
|
|
|
|
|
|
|
|
FILE *xfopen(const char *pathname, const char *mode);
|
2017-04-05 22:12:29 +00:00
|
|
|
int xopen(const char *pathname, int flags);
|
|
|
|
ssize_t xwrite(int fd, const void *buf, size_t count);
|
|
|
|
ssize_t xread(int fd, void *buf, size_t count);
|
|
|
|
ssize_t xxread(int fd, void *buf, size_t count);
|
|
|
|
int xpipe(int pipefd[2]);
|
|
|
|
int xsetns(int fd, int nstype);
|
2017-04-06 22:21:20 +00:00
|
|
|
DIR *xopendir(const char *name);
|
|
|
|
struct dirent *xreaddir(DIR *dirp);
|
2017-04-07 23:37:43 +00:00
|
|
|
pid_t xsetsid();
|
|
|
|
int xsetcon(char *context);
|
|
|
|
int xsocket(int domain, int type, int protocol);
|
|
|
|
int xbind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
|
|
|
|
int xconnect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
|
|
|
|
int xlisten(int sockfd, int backlog);
|
|
|
|
int xaccept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
|
|
|
|
void *xmalloc(size_t size);
|
|
|
|
void *xcalloc(size_t nmemb, size_t size);
|
|
|
|
void *xrealloc(void *ptr, size_t size);
|
|
|
|
ssize_t xsendmsg(int sockfd, const struct msghdr *msg, int flags);
|
|
|
|
ssize_t xrecvmsg(int sockfd, struct msghdr *msg, int flags);
|
2017-04-08 23:25:10 +00:00
|
|
|
int xpthread_create(pthread_t *thread, const pthread_attr_t *attr,
|
2017-04-17 08:36:49 +00:00
|
|
|
void *(*start_routine) (void *), void *arg);
|
2017-04-08 23:25:10 +00:00
|
|
|
int xsocketpair(int domain, int type, int protocol, int sv[2]);
|
2017-04-14 19:23:09 +00:00
|
|
|
int xstat(const char *pathname, struct stat *buf);
|
|
|
|
int xdup2(int oldfd, int newfd);
|
2017-04-15 10:10:54 +00:00
|
|
|
ssize_t xreadlink(const char *pathname, char *buf, size_t bufsiz);
|
|
|
|
int xsymlink(const char *target, const char *linkpath);
|
2017-04-17 08:36:49 +00:00
|
|
|
int xmount(const char *source, const char *target,
|
|
|
|
const char *filesystemtype, unsigned long mountflags,
|
|
|
|
const void *data);
|
|
|
|
int xchmod(const char *pathname, mode_t mode);
|
|
|
|
int xrename(const char *oldpath, const char *newpath);
|
|
|
|
int xmkdir(const char *pathname, mode_t mode);
|
2017-04-04 19:44:13 +00:00
|
|
|
|
2017-04-05 22:12:29 +00:00
|
|
|
// misc.c
|
|
|
|
|
2017-04-14 19:23:09 +00:00
|
|
|
unsigned get_shell_uid();
|
|
|
|
unsigned get_system_uid();
|
|
|
|
unsigned get_radio_uid();
|
2017-04-05 22:12:29 +00:00
|
|
|
int check_data();
|
2017-04-20 14:45:56 +00:00
|
|
|
int file_to_vector(const char* filename, struct vector *v);
|
|
|
|
int vector_to_file(const char* filename, struct vector *v);
|
2017-04-06 22:21:20 +00:00
|
|
|
int isNum(const char *s);
|
2017-04-18 11:32:50 +00:00
|
|
|
ssize_t fdgets(char *buf, size_t size, int fd);
|
2017-04-06 22:21:20 +00:00
|
|
|
void ps(void (*func)(int));
|
|
|
|
void ps_filter_proc_name(const char *filter, void (*func)(int));
|
2017-04-15 10:10:54 +00:00
|
|
|
int create_links(const char *bin, const char *path);
|
2017-04-15 10:33:16 +00:00
|
|
|
void unlock_blocks();
|
2017-04-15 18:42:24 +00:00
|
|
|
void unblock_boot_process();
|
2017-04-17 08:36:49 +00:00
|
|
|
void setup_sighandlers(void (*handler)(int));
|
2017-04-18 11:32:50 +00:00
|
|
|
int run_command(int *fd, const char *path, char *const argv[]);
|
2017-04-21 22:33:40 +00:00
|
|
|
void exec_common_script(const char* stage);
|
2017-04-05 22:12:29 +00:00
|
|
|
|
2017-04-08 23:25:10 +00:00
|
|
|
#endif
|