libsystem: split /proc access apis to proc.{ch}
authorWaLyong Cho <walyong.cho@samsung.com>
Thu, 10 Nov 2016 07:44:50 +0000 (16:44 +0900)
committerWaLyong Cho <walyong.cho@samsung.com>
Thu, 10 Nov 2016 07:44:54 +0000 (16:44 +0900)
And use proc_ prefix.

Change-Id: I555e71a71da3bcbb44f06334b876397578095421
Signed-off-by: WaLyong Cho <walyong.cho@samsung.com>
packaging/libsystem.spec
src/Makefile.am
src/libsystem/libsystem.h
src/libsystem/proc.c
src/libsystem/proc.h [new file with mode: 0644]

index 79d7ea0..7fb9c25 100644 (file)
@@ -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
index e7df956..f1092bc 100644 (file)
@@ -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
index 3dc571e..631a216 100644 (file)
@@ -735,45 +735,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
  * matches are given, return true if a entry satisfied all matches.
index acac082..0881ae8 100644 (file)
 
 #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 (file)
index 0000000..2938f6a
--- /dev/null
@@ -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