From: WaLyong Cho Date: Thu, 10 Nov 2016 07:44:50 +0000 (+0900) Subject: libsystem: split /proc access apis to proc.{ch} X-Git-Tag: submit/tizen/20180322.062032~2^2~2^2~15 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=eb484909d6630f700e8c1a31531511cc729ebe91;p=platform%2Fcore%2Fsystem%2Flibsystem.git libsystem: split /proc access apis to proc.{ch} And use proc_ prefix. Change-Id: I555e71a71da3bcbb44f06334b876397578095421 Signed-off-by: WaLyong Cho --- diff --git a/packaging/libsystem.spec b/packaging/libsystem.spec index 79d7ea0..7fb9c25 100644 --- a/packaging/libsystem.spec +++ b/packaging/libsystem.spec @@ -112,6 +112,7 @@ make check %{_includedir}/libsystem/dbus-util.h %{_includedir}/libsystem/glib-util.h %{_includedir}/libsystem/libsystem.h +%{_includedir}/libsystem/proc.h %{_libdir}/pkgconfig/libsystem.pc %files -n libsystem-sd diff --git a/src/Makefile.am b/src/Makefile.am index e7df956..f1092bc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -50,7 +50,8 @@ libsystem_pkginclude_HEADERS += \ libsystem/config-parser.h \ libsystem/dbus-util.h \ libsystem/glib-util.h \ - libsystem/libsystem.h + libsystem/libsystem.h \ + libsystem/proc.h lib_LTLIBRARIES += \ libsystem.la diff --git a/src/libsystem/libsystem.h b/src/libsystem/libsystem.h index 3dc571e..631a216 100644 --- a/src/libsystem/libsystem.h +++ b/src/libsystem/libsystem.h @@ -734,45 +734,6 @@ bool isdir(const char *path); */ int touch(const char *path); -/** - * @defgroup PROC_GROUP proc group - * - * @brief A set utility library for /proc. Some of library functions - * are only able to be successful root uid with security permissions. - * - * @{ - */ - -/** - * @brief Get string with operator from /proc/cmdline. If foo=bar is - * included in /proc/cmdline and want to get the bar, then: - * \code{.c} - char *buf; - - cmdline_get_str(&buf, "foo="); - * \endcode - * - * @param buf The value string is filled to here. This value has to be - * free-ed by caller. - * @param op An operator string. - * - * @return Result string. This value has to be free-ed by caller. - */ -ssize_t cmdline_get_str(char **buf, const char *op); - -/** - * @brief Get PID of process. - * - * @param pname Process name. - * - * @return PID on successful find. If not found, 0 is returned. And - * -errno is returned on failure. - */ -int pid_of(const char *pname); -/** - * @} - */ - /** * @brief Check mount entry. Multiple matches of conditoin are able to * be set with mnt_fsname, mnt_dir, mnt_type or mnt_opts. If multiple diff --git a/src/libsystem/proc.c b/src/libsystem/proc.c index acac082..0881ae8 100644 --- a/src/libsystem/proc.c +++ b/src/libsystem/proc.c @@ -25,12 +25,7 @@ #include "libsystem.h" -/* In old kernel, this symbol maybe NOT */ -#ifndef TASK_COMM_LEN -#define TASK_COMM_LEN 16 -#endif - -ssize_t cmdline_get_str(char **buf, const char *op) { +ssize_t proc_cmdline_get_str(char **buf, const char *op) { _cleanup_free_ char *cmdline = NULL; char *s, *w, *state; size_t l, ll; @@ -60,7 +55,12 @@ ssize_t cmdline_get_str(char **buf, const char *op) { return -ENOENT; } -int pid_of(const char *pname) { +/* In old kernel, this symbol maybe NOT */ +#ifndef TASK_COMM_LEN +#define TASK_COMM_LEN 16 +#endif + +int proc_pid_of(const char *pname) { _cleanup_closedir_ DIR *dir = NULL; struct dirent *de; int r; diff --git a/src/libsystem/proc.h b/src/libsystem/proc.h new file mode 100644 index 0000000..2938f6a --- /dev/null +++ b/src/libsystem/proc.h @@ -0,0 +1,77 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/* + * libsystem + * + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file proc.h + * + * procfs utility library + * + * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup PROC_GROUP proc group + * + * @brief A set utility library for /proc. Some of library functions + * are only able to be successful root uid with security permissions. + * + * @{ + */ + +/** + * @brief Get string with operator from /proc/cmdline. If foo=bar is + * included in /proc/cmdline and want to get the bar, then: + * \code{.c} + char *buf; + + proc_cmdline_get_str(&buf, "foo="); + * \endcode + * + * @param buf The value string is filled to here. This value has to be + * free-ed by caller. + * @param op An operator string. + * + * @return Result string. This value has to be free-ed by caller. + */ +ssize_t proc_cmdline_get_str(char **buf, const char *op); + +/** + * @brief Get PID of process. + * + * @param pname Process name. + * + * @return PID on successful find. If not found, 0 is returned. And + * -errno is returned on failure. + */ +int proc_pid_of(const char *pname); +/** + * @} + */ + +#ifdef __cplusplus +} +#endif