Skip to content

Commit

Permalink
system-plugin: remove utils
Browse files Browse the repository at this point in the history
  • Loading branch information
zinccyy committed Oct 25, 2022
1 parent af7d10d commit e6ca7da
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 144 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ set(

src/system.c
src/ly_tree.c
src/utils/memory.c

# startup
src/startup/load.c
Expand Down
1 change: 0 additions & 1 deletion src/subscription/change.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "system/data/ntp/server/list.h"
#include "types.h"
#include "umgmt/db.h"
#include "utils/memory.h"

// Load API
#include "system/api/load.h"
Expand Down
17 changes: 8 additions & 9 deletions src/subscription/operational.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "operational.h"
#include "common.h"
#include "ly_tree.h"
#include "utils/memory.h"

#include <sys/sysinfo.h>
#include <sys/utsname.h>
Expand Down Expand Up @@ -155,27 +154,27 @@ static int system_get_platform_info(struct system_platform *platform)
return -1;
}

platform->os_name = xstrndup(uname_data.sysname, strnlen(uname_data.sysname, SYSTEM_UTS_LEN + 1));
platform->os_release = xstrndup(uname_data.release, strnlen(uname_data.release, SYSTEM_UTS_LEN + 1));
platform->os_version = xstrndup(uname_data.version, strnlen(uname_data.version, SYSTEM_UTS_LEN + 1));
platform->machine = xstrndup(uname_data.machine, strnlen(uname_data.machine, SYSTEM_UTS_LEN + 1));
platform->os_name = strndup(uname_data.sysname, strnlen(uname_data.sysname, SYSTEM_UTS_LEN + 1));
platform->os_release = strndup(uname_data.release, strnlen(uname_data.release, SYSTEM_UTS_LEN + 1));
platform->os_version = strndup(uname_data.version, strnlen(uname_data.version, SYSTEM_UTS_LEN + 1));
platform->machine = strndup(uname_data.machine, strnlen(uname_data.machine, SYSTEM_UTS_LEN + 1));

return 0;
}

static void system_free_platform_info(struct system_platform *platform)
{
if (platform->os_name) {
FREE_SAFE(platform->os_name);
free(platform->os_name);
}
if (platform->os_release) {
FREE_SAFE(platform->os_release);
free(platform->os_release);
}
if (platform->os_version) {
FREE_SAFE(platform->os_version);
free(platform->os_version);
}
if (platform->machine) {
FREE_SAFE(platform->machine);
free(platform->machine);
}
}

Expand Down
13 changes: 2 additions & 11 deletions src/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <system.h>
#include <common.h>
#include <context.h>
#include <utils/memory.h>

// stdlib
#include <stdbool.h>
Expand Down Expand Up @@ -53,7 +52,7 @@ int sr_plugin_init_cb(sr_session_ctx_t *running_session, void **private_data)
system_ctx_t *ctx = NULL;

// init context
ctx = xmalloc(sizeof(*ctx));
ctx = malloc(sizeof(*ctx));
*ctx = (system_ctx_t){0};

*private_data = ctx;
Expand Down Expand Up @@ -271,15 +270,7 @@ int sr_plugin_init_cb(sr_session_ctx_t *running_session, void **private_data)

void sr_plugin_cleanup_cb(sr_session_ctx_t *running_session, void *private_data)
{
int error = 0;

system_ctx_t *ctx = (system_ctx_t *) private_data;

// save current running configuration into startup for next time when the plugin starts
error = sr_copy_config(ctx->startup_session, BASE_YANG_MODULE, SR_DS_RUNNING, 0);
if (error) {
SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config() error (%d): %s", error, sr_strerror(error));
}

FREE_SAFE(ctx);
free(ctx);
}
3 changes: 1 addition & 2 deletions src/system/api/dns_resolver/load.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "system/data/dns_resolver/server/list.h"
#include "system/data/dns_resolver/search/list.h"
#include "system/data/ip_address.h"
#include "utils/memory.h"

#include <systemd/sd-bus.h>

Expand Down Expand Up @@ -199,7 +198,7 @@ int system_dns_resolver_load_server(system_ctx_t *ctx, system_dns_server_element
}

// copy to the current server name
tmp_server.name = xstrdup(ip_buffer);
tmp_server.name = strdup(ip_buffer);

error = system_dns_server_list_add(head, tmp_server);
if (error) {
Expand Down
5 changes: 3 additions & 2 deletions src/system/data/dns_resolver/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "search.h"
#include "utils/memory.h"
#include <stdlib.h>
#include <string.h>

void system_dns_search_init(system_dns_search_t *search)
{
Expand All @@ -26,7 +27,7 @@ int system_dns_search_set_domain(system_dns_search_t *search, const char *domain
free((void *) search->domain);
}

search->domain = xstrdup(domain);
search->domain = strdup(domain);

return error;
}
Expand Down
7 changes: 4 additions & 3 deletions src/system/data/dns_resolver/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "server.h"
#include "utils/memory.h"
#include <stdlib.h>
#include <string.h>

void system_dns_server_init(system_dns_server_t *server)
{
Expand All @@ -26,7 +27,7 @@ int system_dns_server_set_name(system_dns_server_t *server, const char *name)
free((void *) server->name);
}

server->name = xstrdup(name);
server->name = strdup(name);

return error;
}
Expand All @@ -40,7 +41,7 @@ int system_dns_server_set_address(system_dns_server_t *server, system_ip_address
if (server->address.value) {
free((void *) server->address.value);
}
server->address.value = xstrdup(address.value);
server->address.value = strdup(address.value);
#endif

return error;
Expand Down
2 changes: 1 addition & 1 deletion src/system/data/ip_address.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "ip_address.h"
#include "utils/memory.h"

#include <arpa/inet.h>
#include <stdlib.h>

void system_ip_address_init(system_ip_address_t *address)
{
Expand Down
15 changes: 8 additions & 7 deletions src/system/data/ntp/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "server.h"
#include "utils/memory.h"
#include <stdlib.h>
#include <string.h>

void system_ntp_server_init(system_ntp_server_t *server)
{
Expand All @@ -27,7 +28,7 @@ int system_ntp_server_set_name(system_ntp_server_t *server, const char *name)
}

if (name) {
server->name = xstrdup(name);
server->name = strdup(name);
}

return error;
Expand All @@ -42,7 +43,7 @@ int system_ntp_server_set_address(system_ntp_server_t *server, const char *addre
}

if (address) {
server->address = xstrdup(address);
server->address = strdup(address);
}

return error;
Expand All @@ -57,7 +58,7 @@ int system_ntp_server_set_port(system_ntp_server_t *server, const char *port)
}

if (port) {
server->port = xstrdup(port);
server->port = strdup(port);
}

return error;
Expand All @@ -72,7 +73,7 @@ int system_ntp_server_set_association_type(system_ntp_server_t *server, const ch
}

if (association_type) {
server->association_type = xstrdup(association_type);
server->association_type = strdup(association_type);
}

return error;
Expand All @@ -86,7 +87,7 @@ int system_ntp_server_set_iburst(system_ntp_server_t *server, const char *iburst
}

if (iburst) {
server->iburst = xstrdup(iburst);
server->iburst = strdup(iburst);
}

return error;
Expand All @@ -101,7 +102,7 @@ int system_ntp_server_set_prefer(system_ntp_server_t *server, const char *prefer
}

if (prefer) {
server->prefer = xstrdup(prefer);
server->prefer = strdup(prefer);
}

return error;
Expand Down
79 changes: 0 additions & 79 deletions src/utils/memory.c

This file was deleted.

28 changes: 0 additions & 28 deletions src/utils/memory.h

This file was deleted.

0 comments on commit e6ca7da

Please sign in to comment.