#include <stdbool.h>
#include <assert.h>
#include <libsyscommon/libgdbus.h>
+#include <libsyscommon/proc.h>
#include <device/display.h>
#include <device/power.h>
goto out;
}
- ret = get_command(pid, comm, sizeof(comm));
+ ret = syscommon_proc_get_comm(pid, comm, sizeof(comm));
if (ret < 0) {
_E("Failed to get command (%d)", ret);
goto out;
* @brief Manage each state's lock. Lock blocks state transition by timeout.
*
*/
+#include <libsyscommon/proc.h>
+
#include "shared/common.h"
#include "ambient-mode.h"
#include "device-interface.h"
return G_SOURCE_REMOVE;
}
- if (!is_app(dl->pid)) {
+ if (!syscommon_proc_is_app(dl->pid)) {
/* For daemon, no need to ask resourced if it is abnormal lock */
// TODO: is it correct?
broadcast_lock_watchdog_expired(dl->pid, dl->state, NULL, dl->time);
display_state_transition_do_state_transition_by_pm_control_event(&recv_data);
return 0;
-}
\ No newline at end of file
+}
#include <libsyscommon/libgdbus.h>
#include <libsyscommon/list.h>
#include <libsyscommon/file.h>
+#include <libsyscommon/proc.h>
#include <device/power-internal.h>
#include "shared/devices.h"
if (pid == -1 || kill(pid, 0) == -1)
goto out;
- get_command(pid, comm, sizeof(comm));
+ syscommon_proc_get_comm(pid, comm, sizeof(comm));
if (is_poweroff_state(next))
CRITICAL_LOG("Pid=%d(%s) sent request for PowerChangeState to %s", pid, comm, state_name(next));
#include <libsyscommon/libgdbus.h>
#include <libsyscommon/libsystemd.h>
#include <libsyscommon/ini-parser.h>
+#include <libsyscommon/proc.h>
#include "dd-deviced.h"
#include "core/log.h"
if (ret < 0)
goto out;
- get_command(ret, comm, sizeof(comm));
+ syscommon_proc_get_comm(ret, comm, sizeof(comm));
if (strncmp(type, "poweroff", sizeof("poweroff")) == 0)
next = DEVICED_POWER_STATE_POWEROFF;
if (ret < 0)
goto out;
- get_command(ret, comm, sizeof(comm));
+ syscommon_proc_get_comm(ret, comm, sizeof(comm));
if (strncmp(type, "poweroff", sizeof("poweroff")) == 0)
next = DEVICED_POWER_STATE_POWEROFF;
#include <linux/input.h>
#include <libsyscommon/libgdbus.h>
#include <libsyscommon/list.h>
+#include <libsyscommon/proc.h>
#include <device/power-internal.h>
#include "shared/devices.h"
pi->pid = pid;
pi->state_bitmap = state;
- get_command(pid, pi->comm, sizeof(pi->comm));
+ syscommon_proc_get_comm(pid, pi->comm, sizeof(pi->comm));
proc_list = g_list_append(proc_list, pi);
_D("pid=%d(%s) added csw for %#"PRIx64, pid, pi->comm, state);
#define BUFF_MAX 255
-#define APP_ATTR_PATH "/proc/%d/attr/current"
-
-int get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size)
-{
- int fd, ret;
- char buf[PATH_MAX + 1];
- char *filename;
-
- snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
- fd = open(buf, O_RDONLY);
- if (fd < 0) {
- errno = ESRCH;
- return -1;
- }
-
- ret = read(fd, buf, PATH_MAX);
- close(fd);
- if (ret < 0)
- return -1;
-
- buf[PATH_MAX] = '\0';
-
- filename = strrchr(buf, '/');
- if (filename == NULL)
- filename = buf;
- else
- filename = filename + 1;
-
- if (cmdline_size < strlen(filename) + 1) {
- errno = EOVERFLOW;
- return -1;
- }
-
- strncpy(cmdline, filename, cmdline_size - 1);
- cmdline[cmdline_size - 1] = '\0';
- return 0;
-}
-
-int is_app(pid_t pid)
-{
- char attr[64];
- size_t len;
- int ret;
-
- ret = get_privilege(pid, attr, sizeof(attr));
- if (ret < 0) {
- _E("Failed to get privilege of PID(%d).", pid);
- return -1;
- }
-
- len = strlen(attr) + 1;
-
- if (!strncmp("System", attr, len))
- return 0;
-
- if (!strncmp("User", attr, len))
- return 0;
-
- if (!strncmp("System::Privileged", attr, len))
- return 0;
-
- return 1;
-}
-
/*
* Helper function
* - Read from sysfs entry
return;
}
-int get_privilege(pid_t pid, char *name, size_t len)
-{
- char path[PATH_MAX];
- char attr[BUFF_MAX];
- size_t attr_len;
- FILE *fp;
-
- snprintf(path, sizeof(path), APP_ATTR_PATH, pid);
-
- fp = fopen(path, "r");
- if (!fp)
- return -errno;
-
- attr_len = fread(attr, 1, sizeof(attr) - 1, fp);
- fclose(fp);
- if (attr_len <= 0)
- return -ENOENT;
-
- attr[attr_len] = '\0';
-
- snprintf(name, len, "%s", attr);
- return 0;
-}
-
#define MODEL_NAME "http://tizen.org/system/model_name"
#define MODEL_EMULATOR "Emulator"
#define _cleanup_fclose_ _cleanup_(__cleanup_fclose_func)
#endif
-int is_app(pid_t pid);
int run_child(int argc, const char *argv[]);
int sys_check_node(char *path);
int get_systemd_reboot_param(char *buf, unsigned bufsize);
int mount_check(const char* path);
void umount_partition_by_kill(const char *path, const int max_retry);
-int get_privilege(pid_t pid, char *name, size_t len);
bool is_emulator(void);
int do_mkdir(const char *path, mode_t mode);
int do_copy_force(const char *src, const char *dst);
void watchdog_notify(void);
-int get_command(pid_t pid, char *comm, size_t len);
#ifdef __cplusplus
}
#include <tzplatform_config.h>
#include <libsyscommon/libgdbus.h>
#include <libsyscommon/list.h>
+#include <libsyscommon/proc.h>
#include "core/log.h"
#include "shared/devices.h"
}
pid = gdbus_connection_get_sender_pid(conn, sender);
- if (is_app(pid) != 0) {
+ if (syscommon_proc_is_app(pid) != 0) {
_E("PID(%d) is not privileged to use tzip.", pid);
ret = -EPERM;
goto out;
}
pid = gdbus_connection_get_sender_pid(conn, sender);
- if (is_app(pid) != 0) {
+ if (syscommon_proc_is_app(pid) != 0) {
_E("PID(%d) is not privileged to use tzip.", pid);
ret = -EPERM;
goto out;