4 * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
22 #include <sys/syscall.h>
23 #include <sys/types.h>
24 #include <systemd/sd-login.h>
26 #include "ctsvc_internal.h"
28 #define CTSVC_SYSTEM_SLICE "system.slice"
30 #define CTSVC_INLINE __attribute__ ((gnu_inline))
32 CTSVC_INLINE inline unsigned int ctsvc_client_get_pid()
34 return (unsigned int)getpid();
37 CTSVC_INLINE inline unsigned int ctsvc_client_get_tid()
39 return (unsigned int)syscall(SYS_gettid);
42 bool ctsvc_client_is_in_system_session()
47 ret = sd_pid_get_slice(getpid(), &slice);
48 if (0 <= ret && slice) {
49 if (STRING_EQUAL == strncmp(slice, CTSVC_SYSTEM_SLICE, strlen(CTSVC_SYSTEM_SLICE))) {
57 ERR("sd_pid_get_slice() Fail(%d)", ret);
66 int ctsvc_client_get_active_uid(uid_t *uid)
68 int active_user_count = 0;
69 uid_t *active_user_list = NULL;
71 active_user_count = sd_get_active_uids(&active_user_list);
72 /* the number of active users is 1 in tizen3.0 */
73 if (1 == active_user_count && active_user_list) {
74 *uid = active_user_list[0];
75 INFO("active uid = %d", *uid);
77 ERR("sd_get_active_uids() Fail(%d)", active_user_count);
78 free(active_user_list);
79 return CONTACTS_ERROR_SYSTEM;
82 free(active_user_list);
83 return CONTACTS_ERROR_NONE;