diff --git a/debian/changelog b/debian/changelog index 2434b8c..dfe47b5 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +libkysdk-system (2.1.1.0-0k0.0) v101; urgency=medium + + *Bug号: + *需求号:21847 新增获取显示系统版本类别接口 + *其他修改: + + -- szm-min Thu, 20 Apr 2023 17:39:35 +0800 + libkysdk-system (2.0.0.0-ok7) yangtze; urgency=medium *Bug号: diff --git a/debian/control b/debian/control index d2feb1e..0d27f2c 100644 --- a/debian/control +++ b/debian/control @@ -410,13 +410,3 @@ Depends: ${shlibs:Depends}, Multi-Arch: same Description: 日志转储服务 -Package: libkysdk-processmanage -Architecture: any -Depends: ${misc:Depends}, - ${shlibs:Depends}, - libdbus-1-3, - libkysdk-log, - libkysdk-config, - libkysdk-utils -Description: 进程管理 - diff --git a/debian/libkysdk-processmanage.install b/debian/libkysdk-processmanage.install deleted file mode 100644 index 4c85ecf..0000000 --- a/debian/libkysdk-processmanage.install +++ /dev/null @@ -1,4 +0,0 @@ -development-files/kysdk-processmanage.pc usr/share/pkgconfig/ -src/processmanage/processStateManage.service lib/systemd/system -src/processmanage/com.kylin.processStateManage.conf etc/dbus-1/system.d -bin/processStateManage usr/bin/ diff --git a/development-files/kysdk-processmanage.pc b/development-files/kysdk-processmanage.pc deleted file mode 100644 index fb3fa80..0000000 --- a/development-files/kysdk-processmanage.pc +++ /dev/null @@ -1,4 +0,0 @@ -Name: process-state-manage -Description: manage process oom_score_adj and oom_score_adj_child -Requires: kysdk-log kysdk-config libsystemd dbus-1 dbus-glib-1 -Version: 2.0.0 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3054fba..6e76c66 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,4 +21,4 @@ add_subdirectory(realtime) add_subdirectory(kysdkdbus) add_subdirectory(libkysdk-system-javascript-http) add_subdirectory(libkysdk-system-javascript-websocket) -add_subdirectory(processmanage) +# add_subdirectory(processmanage) diff --git a/src/processmanage/CMakeLists.txt b/src/processmanage/CMakeLists.txt deleted file mode 100755 index 67abeb7..0000000 --- a/src/processmanage/CMakeLists.txt +++ /dev/null @@ -1,54 +0,0 @@ - -project(processStateManage) -# set(CMAKE_INSTALL_PREFIX "/usr") -# set(BUILD_BINDIR "${CMAKE_INSTALL_PREFIX}/bin") #用过参数指定安装路径 -# set(SYSCONFDIR "/etc" CACHE STRING "system config dir") -# set(SYSTEMD_SYSTEM_UNIT_DIR "/lib/systemd/system" CACHE STRING "system config dir") - -find_package(PkgConfig) -pkg_check_modules (GLIB2 REQUIRED glib-2.0) -pkg_check_modules (DBUS1 REQUIRED dbus-1) -pkg_check_modules (KYLOG kysdk-log) -pkg_check_modules (KYCOF kysdk-config) -pkg_check_modules (KYBASE kysdk-base) -pkg_check_modules (DBUSGLIB1 REQUIRED dbus-glib-1) - - - -link_directories( ${GLIB2_LIBRARY_DIRS} - ${DBUS1_LIBRARY_DIRS} - ${DBUSGLIB1_LIBRARY_DIRS} - ${KYBASE_INCLUDE_DIRS} - ${KYCONFIG_INCLUDE_DIRS} - ${KYLOG_INCLUDE_DIRS} - ) - - - -cmake_minimum_required(VERSION 3.16) - -set(processStateManage-src main.c) - -add_executable(processStateManage ${processStateManage-src}) -target_link_libraries( processStateManage ${GLIB2_LIBRARIES} - ${GIO2_LIBRARIES} - ${DBUS1_LIBRARIES} - ${DBUSGLIB1_LIBRARIES} - ${KYBASE_LIBRARIES} - ${KYCONFIG_LIBRARIES} - ${KYLOG_LIBRARIES} - ) - -target_link_directories(processStateManage PRIVATE ${KYLOG_LIBRARY_DIRS}) -install(TARGETS processStateManage DESTINATION bin) - -INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR} - ${DBUS1_INCLUDE_DIRS} - ${GLIB2_INCLUDE_DIRS} - /usr/include/gtk-3.0/ - /usr/include/pango-1.0/ - /usr/include/harfbuzz/ - /usr/include/cairo/ - /usr/include/gdk-pixbuf-2.0/ - /usr/include/atk-1.0/) - diff --git a/src/processmanage/com.kylin.processStateManage.conf b/src/processmanage/com.kylin.processStateManage.conf deleted file mode 100644 index ede3dea..0000000 --- a/src/processmanage/com.kylin.processStateManage.conf +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/processmanage/main.c b/src/processmanage/main.c deleted file mode 100755 index 5c0f4c8..0000000 --- a/src/processmanage/main.c +++ /dev/null @@ -1,861 +0,0 @@ -#include -#include -#include -#include -// #include -#include /* for glib main loop */ -#include -#include -#include -#include -#include -#include -#include -// #include - -#define CONF_PATH "/etc/kysdk/kysdk-system/" -// #define CONF_PATH "/home/wgs/code/dbus/" -#define CONF_FILE CONF_PATH"processStateSetAcl.conf" -#define LINEMAX 1024 - -enum oom_score_adj{ - NOTALLOW = 1, - FIXEVALUEL, - FREECONFIG, - -}; -enum oom_score_adj_child{ - NOTALLOW_CHILD = 1, - FIXEVALUEL_CHILD, - FREECONFIG_CHILD, -}; - -const char *version = "1.0"; -int confId = 0; - -const char *server_introspection_xml = - DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE - "\n" - - " \n" - " \n" - " \n" - " \n" - " \n" - - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - - " \n" - " \n" - " \n" - " \n" - - " \n" - " \n" - " \n" - " \n" - - "\n"; -static int config_file_compare_auth(int id, const char *auth, char *buf) -{ - char **keylist; - char *tmpkey; - int k_index = 0; - - keylist = kdk_conf_list_key(id, auth); - if (*keylist == NULL){ - return 1; - } - ASSERT_NOT_NULL(keylist, -1); - while ((tmpkey = keylist[k_index])) - { - const char *tmpval = kdk_conf_get_value(id, auth, tmpkey); - if(tmpval != NULL && buf && strlen(buf) != 0) - { - if (!strcmp(tmpval, buf)) - { - return 0; - } - else - { - k_index++; - continue; - } - } - } - return -1; -} - -static int config_file_compare_group(char** const grouplist, int id, const char *group, char *buf) -{ - int index = 0; - int r = -1; - int key = -1; - const char *tmpgroup; - while ((tmpgroup = grouplist[index])) - { - if (!strcmp(tmpgroup, group)) - { - r = config_file_compare_auth(id, group, buf); - key = 0; - if (r) - { - return r; - } - } - index++; - } - if (key < 0) - { - return -1; - } - return 0; -} - -static int process_acl_check(const char *configpath, char *buf) -{ - int id = 0; - int r = -1; - const char *whitelist = "whitelist"; - - id = kdk_conf_init(configpath); - - if (id <= 0) - return -1; - - char** const grouplist = kdk_conf_list_group(id); - ASSERT_NOT_NULL(grouplist, -1); - - r = config_file_compare_group(grouplist, id, whitelist, buf); - if(r < 0) - { - goto exit; - } - -exit: - kdk_conf_destroy(id); - return r; -} - -/** - * @brief 通过进程名字查看是该进程是否在配置文件中 - * - * @param configpath 配置文件的路径 - * @param processName 需要查找的进程名 - * @return int 若在配置文件中,返回0;若不再配置文件中,返回-1 - */ -static int process_name_check(const char*configpath,const char* processName) -{ - int id = 0; - int index = 0; - const char *nameKey = "name"; - char* tmpgroup; - - confId = kdk_conf_init(configpath); - - if (confId <= 0) - return -1; - - char** const grouplist = kdk_conf_list_group(confId); - ASSERT_NOT_NULL(grouplist, -1); - - while ((tmpgroup = grouplist[index])) - { - // fprintf(stderr,"%s,%d\n",tmpgroup,index); - if (!strcmp(tmpgroup, processName)) - { - const char *tmpval = kdk_conf_get_value(confId, tmpgroup, nameKey); - // fprintf(stderr,"tmpgroup = %s,processName = %s,tmpval = %s\n",tmpgroup,processName,tmpval); - - if (!strcmp(tmpval, processName)) - { - return 0; - } - - } - index++; - } - return -1; - -exit: - kdk_conf_destroy(confId); -} - -/** - * @brief 通过进程名和key值查找key对应的value - * - * @param configpath 配置文件的路径 - * @param processName 需要查找的进程名 - * @param key 需要查找key - * @param out 要查找的key对应的value - - * @return int 若查找到对应的value,返回0;否则,返回-1 - */ -static int get_value_by_key_process(const char*configpath, const char *processName,const char* key,char* out) -{ - int ret = -1; - const char *tmpval = NULL; - - - ret = process_name_check(configpath,processName); - if(ret == -1) - return ret; - - tmpval = kdk_conf_get_value(confId, processName, key); - if(tmpval) - { - strcpy(out,tmpval); - return 0; - } - return -1; -} - -//查找调用信号者的进程pid -static int get_dbus_sender_pid(DBusConnection *conn, DBusMessage *m, pid_t* pit_out) -{ - bool bRet = 0; - int iRet = 0; - int r = 0; - DBusPendingCall *pending_call = NULL; - DBusError err; - DBusMessage *reply = NULL; - DBusMessage *message = NULL; - - const char * sender = dbus_message_get_sender(m); - if(sender) - { - - message = dbus_message_new_method_call( - "org.freedesktop.DBus", - "/org/freedesktop/DBus", - "org.freedesktop.DBus", - "GetConnectionUnixProcessID"); - if(message) - { - - DBusMessageIter iter; - - dbus_error_init(&err); - dbus_message_iter_init_append(message, &iter); - - bRet = dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &sender); - if(!bRet){ - iRet = -1; - }; - bRet = dbus_connection_send_with_reply(conn, message, &pending_call, 3000); - if(!bRet){ - iRet = -1; - }; - - if(!pending_call) - goto exit; - dbus_pending_call_block(pending_call); - reply = dbus_pending_call_steal_reply(pending_call); - if(!reply) - goto exit; - - dbus_message_get_args(reply, &err, DBUS_TYPE_UINT32, pit_out, DBUS_TYPE_INVALID); - exit: - if(pending_call) - dbus_pending_call_unref(pending_call); - if(reply) - dbus_message_unref(reply); - if(dbus_error_is_set(&err)) - dbus_error_free(&err); - dbus_message_unref(message); - - return iRet; - } - return -1; - } - - return -1; -} - -static int get_client_by_proc_exe(const char *exe_path, char buf[]) -{ - int result = readlink(exe_path, buf, LINEMAX - 1); - - if (result < 0 || (result >= LINEMAX - 1)) - { - return -1; - } - - buf[result] = '\0'; - - return 0; -} - -static int get_client_by_proc_cmdline( const char *cmdline, char buf[]) -{ - FILE *fp = NULL; - - if (access(cmdline, F_OK)) - { - return -1; - } - //---------读取cmdline - if ((fp = fopen(cmdline, "rb")) == NULL) - { - return -1; - } - fscanf(fp, "%s", buf); - fclose(fp); - - return 0; -} -//通过进程pid查找进程名 -static int get_name_by_pid(int pid, char buf[], char **spos) -{ - int result = 0; - char cmdline[LINEMAX] = ""; - char exe_path[LINEMAX] = ""; - char *new_spos; - char tmp1[512]; - FILE *fp = NULL; - - sprintf(exe_path, "/%s/%d/%s", "proc", pid, "exe"); - sprintf(cmdline, "/%s/%d/%s", "proc", pid, "cmdline"); - - if (access(exe_path, F_OK)) - { - result = get_client_by_proc_cmdline(cmdline, buf); - } - else - { - result = get_client_by_proc_exe(exe_path, buf); - } - - if(result) - return -1; - -//如果在cmdline中读取到的是以python开头,则选取后续字符为进程。 - if (!strstartswith(buf, "/usr/bin/python")) - { - if ((fp = fopen(cmdline, "rb")) == NULL) - { - return -1; - } - fscanf(fp, "%s", tmp1); - fclose(fp); - new_spos = tmp1; - new_spos += strlen(tmp1); - while (*new_spos == '\0' || *new_spos == '.') - { - new_spos++; - } - // if (strstartswith(new_spos, "/usr") && *new_spos == '/'){ - // new_spos++; - // } - *spos = strdup(new_spos); - - } - else{ - - } - - return 0; -} -//查找信号调用者的进程名 -static int get_dbus_sender_name(DBusConnection *conn, DBusMessage *m,char buf[], char **spos,int*p) -{ - int ret = -1; - pid_t pid; - ret = get_dbus_sender_pid(conn,m,&pid); - if(ret == -1 ) - { - - return ret; - } - if(pid <= 0) - return -1; - fprintf(stderr,"current pid = %d\n",pid); - *p = pid; - fprintf(stderr,"current pid = %d\n",pid); - ret = get_name_by_pid(pid, buf, spos); - if(ret == -1 ) - { - return ret; - } - return 0; - -} - -//根据进程的pid写入文件/proc/{pid}/oom_score_adj -static int write_to_oom_score_adj(int pid,int om ) -{ - char oomScoreAdj[LINEMAX] = ""; - int res = -1; - - FILE *fp = NULL; - - sprintf(oomScoreAdj, "/%s/%d/%s", "proc", pid, "oom_score_adj"); - if (access(oomScoreAdj, F_OK)) - { - return -1; - } - - if ((fp = fopen(oomScoreAdj, "wb")) == NULL) - { - return -1; - } - res = fprintf(fp,"%d",om); - if(res > 0) - { - fclose(fp); - return 0; - } - fclose(fp); - return -1; - -} - -//根据进程pid写入文件/proc/{pid}/oom_score_adj_child -static int write_to_oom_score_adj_child(int pid,int om ) -{ - char oomScoreAdj[LINEMAX] = ""; - int res = -1; - - FILE *fp = NULL; - - sprintf(oomScoreAdj, "/%s/%d/%s", "proc", pid, "oom_score_adj_child"); - if (access(oomScoreAdj, F_OK)) - { - return -1; - } - - if ((fp = fopen(oomScoreAdj, "wb")) == NULL) - { - return -1; - } - res = fprintf(fp,"%d",om); - if(res > 0) - { - fclose(fp); - return 0; - } - fclose(fp); - return -1; - -} - -//根据进程pid写入文件/proc/{pid}/oom_score_adj_child_enable -static int write_to_oom_score_adj_child_enable(int pid,int om ) -{ - char oomScoreAdj[LINEMAX] = ""; - int res = -1; - - FILE *fp = NULL; - - sprintf(oomScoreAdj, "/%s/%d/%s", "proc", pid, "oom_score_adj_child_enable"); - if (access(oomScoreAdj, F_OK)) - { - return -1; - } - - if ((fp = fopen(oomScoreAdj, "wb")) == NULL) - { - return -1; - } - res = fprintf(fp,"%d",om); - if(res > 0) - { - fclose(fp); - return 0; - } - fclose(fp); - return -1; - -} - -DBusHandlerResult server_get_all_properties_handler(DBusConnection *conn, DBusMessage *reply) -{ - DBusHandlerResult result; - DBusMessageIter array, dict, iter, variant; - const char *property = "Version"; - - /* - * All dbus functions used below might error due to out of - * memory error. If one of them fails, we assume that all - * following functions will error too, including - * dbus_connection_send(). - */ - result = DBUS_HANDLER_RESULT_NEED_MEMORY; - - dbus_message_iter_init_append(reply, &iter); - dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "{sv}", &array); - - /* Append all properties name/value pairs */ - property = "Version"; - dbus_message_iter_open_container(&array, DBUS_TYPE_DICT_ENTRY, NULL, &dict); - dbus_message_iter_append_basic(&dict, DBUS_TYPE_STRING, &property); - dbus_message_iter_open_container(&dict, DBUS_TYPE_VARIANT, "s", &variant); - dbus_message_iter_append_basic(&variant, DBUS_TYPE_STRING, &version); - dbus_message_iter_close_container(&dict, &variant); - dbus_message_iter_close_container(&array, &dict); - - dbus_message_iter_close_container(&iter, &array); - - if (dbus_connection_send(conn, reply, NULL)) - result = DBUS_HANDLER_RESULT_HANDLED; - return result; -} - -DBusHandlerResult dbus_message_handler(DBusConnection *conn, DBusMessage *message, void *data) -{ - DBusHandlerResult result; - DBusMessage *reply = NULL; - DBusError err; - int repValue = -1,ret = -1; - int oom_score,oom_score_child; - int pid = 0; - char processName[LINEMAX]; - char* scriptProcessName = NULL; - char tmpValue[128]; - - klog_debug("Got D-Bus request: %s.%s on %s\n", - dbus_message_get_interface(message), - dbus_message_get_member(message), - dbus_message_get_path(message)); - /* - * Does not allocate any memory; the error only needs to be - * freed if it is set at some point. - */ - dbus_error_init(&err); - - if (dbus_message_is_method_call(message, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) { - if (!(reply = dbus_message_new_method_return(message))) - goto exit; - - dbus_message_append_args(reply, - DBUS_TYPE_STRING, &server_introspection_xml, - DBUS_TYPE_INVALID); - - } else if (dbus_message_is_method_call(message, DBUS_INTERFACE_PROPERTIES, "Get")) { - const char *interface, *property; - - if (!dbus_message_get_args(message, &err, - DBUS_TYPE_STRING, &interface, - DBUS_TYPE_STRING, &property, - DBUS_TYPE_INVALID)) - goto exit; - - if (!(reply = dbus_message_new_method_return(message))) - goto exit; - - // result = server_get_properties_handler(property, conn, reply); - // dbus_message_unref(reply); - return result; - - }else if (dbus_message_is_method_call(message, DBUS_INTERFACE_PROPERTIES, "GetAll")) { - if (!(reply = dbus_message_new_method_return(message))) - goto exit; - - result = server_get_all_properties_handler(conn, reply); - dbus_message_unref(reply); - return result; - - }else if (dbus_message_is_method_call(message, "com.kylin.processStateManage", "SetOomScore")) { - if (!(reply = dbus_message_new_method_return(message))) - goto exit; - - if (!dbus_message_get_args(message, &err, - DBUS_TYPE_INT32, &oom_score, - DBUS_TYPE_INVALID)) - goto exit; - - ret = get_dbus_sender_name(conn, message, processName, &scriptProcessName, &pid); - if(ret == 0) - { - if(scriptProcessName) - strcpy(processName,scriptProcessName); - if(processName) - { - unsigned int state; - // fprintf(stderr,"proces name = %s\n",processName); - ret = get_value_by_key_process(CONF_FILE,processName,"allow",tmpValue); - if(ret == 0) - { - state = atoi(tmpValue); - if(state == NOTALLOW) //不允许更改,则直接返回 -1 - { - // fprintf(stderr,"allow = %d\n",state); - repValue = -1; - }else if(state == FIXEVALUEL) //允许设置成固定值,则将配置文件的oom_score直接写入文件中 - { - // fprintf(stderr,"allow = %d\n",state); - int file_oom; - ret = get_value_by_key_process(CONF_FILE,processName,"oom_score",tmpValue); - if(ret == 0) - { - file_oom = atoi(tmpValue); - ret = write_to_oom_score_adj(pid,file_oom); - if(ret == 0) - { - repValue = 0; - // fprintf(stderr,"allow = %d,om = %d\n",state,file_oom); - } - - } - }else if(state == FREECONFIG) //可以配置,需要将设置进来OM中大于等于文件中的OM值 - { - // fprintf(stderr,"allow = %d\n",state); - int file_oom; - ret = get_value_by_key_process(CONF_FILE,processName,"oom_score",tmpValue); - if(ret == 0) - { - file_oom = atoi(tmpValue); - if(file_oom <= oom_score) - { - // fprintf(stderr,"file_oom = %d,oom_score = %d\n",file_oom,oom_score); - ret = write_to_oom_score_adj(pid,oom_score); - if(ret == 0) - { - repValue = 0; - } - }else{ - repValue = -1; - } - } - - } - } - } - } - - dbus_message_append_args(reply, - DBUS_TYPE_INT32, &repValue, - DBUS_TYPE_INVALID); - - if(scriptProcessName) { - free(scriptProcessName); - scriptProcessName = NULL; - } - }else if (dbus_message_is_method_call(message, "com.kylin.processStateManage", "SetOomScoreChild")){ - if (!(reply = dbus_message_new_method_return(message))) - goto exit; - - if (!dbus_message_get_args(message, &err, - DBUS_TYPE_INT32, &oom_score_child, - DBUS_TYPE_INVALID)) - goto exit; - ret = get_dbus_sender_name(conn, message, processName, &scriptProcessName, &pid); - if(ret == 0) - { - if(scriptProcessName) - strcpy(processName,scriptProcessName); - if(processName) - { - unsigned int state; - // fprintf(stderr,"proces name = %s\n",processName); - ret = get_value_by_key_process(CONF_FILE,processName,"allow_inheritance",tmpValue); - if(ret == 0) - { - state = atoi(tmpValue); - if(state == NOTALLOW_CHILD) //不可以设置是否关闭继承 child_enalbe 0 - { - ret = write_to_oom_score_adj_child_enable(pid, 0); - if(ret == 0) - { - - } - // fprintf(stderr,"allow = %d\n",state); - repValue = -1; - }else if(state == FIXEVALUEL_CHILD) //可以设置关闭继承,则将配置文件的oom_score直接写入文件中 child_enalbe 1 - { - // fprintf(stderr,"allow = %d\n",state); - ret = write_to_oom_score_adj_child_enable(pid, 1); - if(ret == 0) - { - int file_oom; - ret = get_value_by_key_process(CONF_FILE,processName,"oom_score_child",tmpValue); - if(ret == 0) - { - file_oom = atoi(tmpValue); - ret = write_to_oom_score_adj_child(pid, file_oom); - if(ret == 0) - { - repValue = 0; - // fprintf(stderr,"allow = %d,om = %d\n", state, file_oom); - } - } - } - }else if(state == FREECONFIG_CHILD) //可以设置关闭继承,需要将设置进来OM中大于等于文件中的OM值 - { - // fprintf(stderr,"allow = %d\n",state); - ret = write_to_oom_score_adj_child_enable(pid, 1); - if(ret == 0) - { - int file_oom; - ret = get_value_by_key_process(CONF_FILE,processName,"oom_score_child",tmpValue); - if(ret == 0) - { - file_oom = atoi(tmpValue); - if(file_oom <= oom_score_child) - { - // fprintf(stderr,"file_oom = %d,oom_score_child = %d\n",file_oom,oom_score_child); - ret = write_to_oom_score_adj_child(pid,oom_score_child); - if(ret == 0) - { - repValue = 0; - } - }else{ - repValue = -1; - } - } - } - - - } - } - } - } - - dbus_message_append_args(reply, - DBUS_TYPE_INT32, &repValue, - DBUS_TYPE_INVALID); - - if(scriptProcessName) { - free(scriptProcessName); - scriptProcessName = NULL; - } - }else - { - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - } - -exit: - if (dbus_error_is_set(&err)) { - if (reply) - dbus_message_unref(reply); - reply = dbus_message_new_error(message, err.name, err.message); - dbus_error_free(&err); - } - - /* - * In any cases we should have allocated a reply otherwise it - * means that we failed to allocate one. - */ - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - - /* Send the reply which might be an error one too. */ - result = DBUS_HANDLER_RESULT_HANDLED; - if (!dbus_connection_send(conn, reply, NULL)) - result = DBUS_HANDLER_RESULT_NEED_MEMORY; - dbus_message_unref(reply); - - return result; -} - -const DBusObjectPathVTable dbus_vtable = { - .message_function = dbus_message_handler -}; - -static int emit_signal_for_online(DBusConnection *conn, const char* signame, const char* dscp) -{ -#define CHECK_STEP_FAILED() if(!bRet){iFailed = 1;} - - bool bRet = 0; - int iFailed = 0; - DBusMessage *msg; - DBusMessageIter iter, dict_iter; - - msg = dbus_message_new_signal("/com/kylin/processStateManage", - "com.kylin.processStateManage", - signame); - - if(!msg) - goto error; - - dbus_message_iter_init_append(msg, &iter); - - bRet = dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &dscp); - CHECK_STEP_FAILED(); - bRet = dbus_connection_send(conn, msg, NULL); - CHECK_STEP_FAILED(); - - dbus_connection_flush(conn); - - dbus_message_unref(msg); - - if(!iFailed) - return 0; - -error: - klog_debug("[ERROR] process Permission server online %s failed\n", signame); - return -1; -} - - - -int main(int argc, char **argv) -{ - int r = 0; - DBusError err; - GMainLoop *mainloop; - DBusConnection *BusConn; - - - dbus_error_init(&err); - BusConn = dbus_bus_get(DBUS_BUS_SYSTEM, &err); - if (!BusConn) { - klog_debug("Failed to get a session DBus connection: %s\n", err.message); - goto error; - } - - r = dbus_bus_request_name(BusConn, "com.kylin.processStateManage", DBUS_NAME_FLAG_REPLACE_EXISTING , &err); - if (r != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { - klog_debug("Failed to request name on bus: %s\n", err.message); - goto error; - } - if (!dbus_connection_register_object_path(BusConn, "/com/kylin/processStateManage", &dbus_vtable, NULL)) { - klog_debug("Failed to register a object path for 'TestObject'\n"); - goto error; - } - - /* Set up the DBus connection to work in a GLib event loop */ - dbus_connection_setup_with_g_main(BusConn, NULL); - - r = emit_signal_for_online(BusConn,"SignalOnline","online"); - if(r) - klog_debug("[ERROR] process process Permission emit OnLine signal failed\n"); - else - klog_debug("process Permission emit OnLine signal succ\n"); - - klog_debug("Now process Permission prepare to run main_loop\n"); - - /* event-loop */ - mainloop = g_main_loop_new(NULL, 0); - - g_main_loop_run(mainloop); - - g_main_loop_unref(mainloop); - - return EXIT_SUCCESS; - -error: - dbus_error_free(&err); - return EXIT_FAILURE; -} - - - - diff --git a/src/processmanage/processStateManage.service b/src/processmanage/processStateManage.service deleted file mode 100644 index cb6c008..0000000 --- a/src/processmanage/processStateManage.service +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description=processStateManage Daemon -After=dbus.service - -[Service] -#BusName=processStateManage -#Environment=PATH=/sbin:/usr/bin -ExecStart=/usr/bin/processStateManage -Restart=always -[Install] -WantedBy=multi-user.target - diff --git a/src/processmanage/processStateSetAcl.conf b/src/processmanage/processStateSetAcl.conf deleted file mode 100644 index 7b2f7e0..0000000 --- a/src/processmanage/processStateSetAcl.conf +++ /dev/null @@ -1,58 +0,0 @@ -#管理配置这块,需要几个字段了 -#1.进程名 -#2.是否允许本进程设置oom值,可选项:不允许、固定值、可自由配置 -#3.第2点允许的情况下,oom值(固定值)、最小oom值(可自由配置) - -#4.是否允许设置是否关闭继承,可选项:不可以、固定child值、可手动配置child值 -#5.第4点允许的情况下,child值(固定值)、最小child值(可自由配置) -#1-----不允许 -#2-----固定值 -#3-----自由配置 -#如果允许子进程继承父进程(oom_score_adj_child_enable值为1), -#则父进程的oom_score_adj_child和子进程的oom_score_adj一致,, - -#如果不允许子进程继承父进程(oom_score_adj_child_enable值为0) -#,则父进程的oom_score_adj和子进程的oom_score_adj一致, -[/usr/bin/kylin-weather1] -name=/usr/bin/kylin-weather -allow=2 -oom_score=-500 -allow_inheritance=2 -oom_score_child=-500 - - -[/usr/bin/kylin-weather2] -name=/usr/bin/kylin-weather2 -allow=25 -oom_score=-25250 -allow_inheritance=2525 -oom_score_child=-52454500 - -[/usr/bin/kylin-weather] -name=/usr/bin/kylin-weather -allow=23 -oom_score=-500 -allow_inheritance=2 -oom_score_child=-500 - - -[/home/wgs/code/build-dbus-test-unknown-Debug/dbus-test] -name=/home/wgs/code/build-dbus-test-unknown-Debug/dbus-test -allow=3 -oom_score=-500 -allow_inheritance=2 -oom_score_child=-500 - - - - - - - - - - - -/usr/bin/aaa , enum{1,2,3}, int value_process , enum {1,2,3} , int value_child - - diff --git a/src/systeminfo/libkysysinfo.c b/src/systeminfo/libkysysinfo.c index 4fc2e26..c23b5b3 100644 --- a/src/systeminfo/libkysysinfo.c +++ b/src/systeminfo/libkysysinfo.c @@ -937,6 +937,27 @@ out: return res; } +char* kdk_system_get_systemCategory() +{ + char *vername = (char *)malloc(sizeof(char) * 50); +#ifdef __linux__ + FILE *fp = fopen("/etc/LICENSE", "r"); + if (! fp) + { + strcpy(vername, "none"); + return vername; + } + + vername = get_val_from_file(fp, "SUBCLASS"); + if (!vername) + return NULL; + strstrip(vername, '\n'); + strstrip(vername, '\"'); + fclose(fp); +#endif + return vername; +} + inline void kdk_resolving_freeall(char **list) { if (! list) diff --git a/src/systeminfo/libkysysinfo.h b/src/systeminfo/libkysysinfo.h index 90fd5a1..1289da7 100644 --- a/src/systeminfo/libkysysinfo.h +++ b/src/systeminfo/libkysysinfo.h @@ -138,7 +138,7 @@ extern char* kdk_system_get_hostCloudPlatform(); extern bool kdk_system_is_zyj(void); /** - * @brief 获取系统版本号 + * @brief 获取系统版本号/补丁版本号 * * @return version_t 该系统版本号的详细信息,具体信息自取 */ @@ -153,6 +153,14 @@ extern version_t kdk_system_get_version_detaile(); extern char** kdk_system_get_resolving_power(); +/** + * @brief 获取显示系统版本类别 + * + * @return char* 成功返回字符串系统版本类别,失败返回NULL。返回的字符串需要被 free 释放 + */ + +extern char* kdk_system_get_systemCategory(); + /** * @brief 用于回收字符串列表 * diff --git a/src/systeminfo/test/kysysinfo_test.c b/src/systeminfo/test/kysysinfo_test.c index 213fe64..6ab022b 100644 --- a/src/systeminfo/test/kysysinfo_test.c +++ b/src/systeminfo/test/kysysinfo_test.c @@ -65,9 +65,5 @@ int main() printf("系统版本类别 = %s\n", ver); free(ver); - ver = kdk_system_get_cloudPlatformType(); - printf("云平台类型 = %s\n", ver); - free(ver); - return 0; } diff --git a/src/systemtime/libkydate.c b/src/systemtime/libkydate.c index ead4283..bf7aa15 100644 --- a/src/systemtime/libkydate.c +++ b/src/systemtime/libkydate.c @@ -15,6 +15,7 @@ #include #include +#define SAFE_FREE(x) if (x) {free(x); x = NULL;} #define DATEFORMAT "DATEFORMAT" #define PATH_MAX 50