Skip to content
Snippets Groups Projects
Commit 57ca9f4f authored by Eric Vidal's avatar Eric Vidal :speech_balloon:
Browse files

add service_resolve_write_tmp and state_write_tmp function to be able to write...

add service_resolve_write_tmp and state_write_tmp function to be able to write those files at a temporary directory
parent 1b9d6ee7
No related branches found
No related tags found
No related merge requests found
......@@ -312,7 +312,8 @@ extern int service_resolve_copy(resolve_service_t *dst, resolve_service_t *res)
extern int service_resolve_get_field_tosa(stralloc *sa, resolve_service_t *res, resolve_service_enum_t field) ;
extern int service_resolve_modify_field(resolve_service_t *res, resolve_service_enum_t field, char const *data) ;
extern int service_resolve_read_cdb(cdb *c, resolve_service_t *res) ;
extern int service_resolve_write(resolve_service_t *res) ;
extern void service_resolve_write(resolve_service_t *res) ;
extern void service_resolve_write_tmp(resolve_service_t *res, char const *dst, uint8_t force) ;
extern int service_resolve_write_cdb(cdbmaker *c, resolve_service_t *sres) ;
extern void service_enable_disable(graph_t *g, resolve_service_t *res, resolve_service_t *ares, unsigned int areslen, uint8_t action, visit_t *visit) ;
/* avoid circular dependencies by prototyping the ss_state_t instead
......
......@@ -83,6 +83,7 @@ extern void state_unpack(char *pack, ss_state_t *sta) ;
extern void state_set_flag(ss_state_t *sta, int flags,int flags_val) ;
extern int state_check(resolve_service_t *res) ;
extern int state_write(ss_state_t *sta, resolve_service_t *res) ;
extern int state_write_tmp(ss_state_t *sta, char const *tmp) ;
extern int state_read(ss_state_t *sta, resolve_service_t *res) ;
extern int state_messenger(resolve_service_t *res, uint32_t flag, uint32_t value) ;
......
......@@ -12,9 +12,10 @@ service_resolve_array_search.o
service_resolve_copy.o
service_resolve_get_field_tosa.o
service_resolve_modify_field.o
service_resolve_read_cdb.o
service_resolve_write.o
service_resolve_read_cdb.o
service_resolve_write_cdb.o
service_resolve_write_tmp.o
-loblibs
-lskarnet
/*
* service_resolve_write_tmp.c
*
* Copyright (c) 2018-2021 Eric Vidal <eric@obarun.org>
*
* All rights reserved.
*
* This file is part of Obarun. It is subject to the license terms in
* the LICENSE file found in the top-level directory of this
* distribution.
* This file may not be copied, modified, propagated, or distributed
* except according to the terms contained in the LICENSE file./
*/
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <oblibs/log.h>
#include <oblibs/string.h>
#include <oblibs/directory.h>
#include <66/service.h>
#include <66/constants.h>
#include <66/parse.h>
void service_resolve_write_tmp(resolve_service_t *res, char const *dst, uint8_t force)
{
log_flow() ;
char *name = res->sa.s + res->name ;
size_t dstlen = strlen(dst) ;
char dest[dstlen + SS_RESOLVE_LEN + 1] ;
resolve_wrapper_t_ref wres = resolve_set_struct(DATA_SERVICE, res) ;
auto_strings(dest, dst, SS_RESOLVE) ;
if (access(dest, F_OK) < 0) {
log_trace("create directory: ", dest) ;
if (!dir_create_parent(dest, 0755)) {
parse_cleanup(res, dst, force) ;
free(wres) ;
log_dieusys(LOG_EXIT_SYS, "create directory: ", dest) ;
}
}
dest[dstlen] = 0 ;
log_trace("write resolve file: ", dest, SS_RESOLVE, "/", name) ;
if (!resolve_write(wres, dest, name)) {
parse_cleanup(res, dst, force) ;
free(wres) ;
log_dieusys(LOG_EXIT_SYS, "write resolve file: ", dest, SS_RESOLVE, "/", name) ;
}
free(wres) ;
}
......@@ -5,6 +5,7 @@ state_read.o
state_rmfile.o
state_set_flag.o
state_unpack.o
state_write_tmp.o
state_write.o
-loblibs
-lskarnet
......
/*
* state_write_tmp.c
*
* Copyright (c) 2018-2021 Eric Vidal <eric@obarun.org>
*
* All rights reserved.
*
* This file is part of Obarun. It is subject to the license terms in
* the LICENSE file found in the top-level directory of this
* distribution.
* This file may not be copied, modified, propagated, or distributed
* except according to the terms contained in the LICENSE file./
*/
#include <string.h>
#include <unistd.h>
#include <oblibs/log.h>
#include <oblibs/string.h>
#include <oblibs/directory.h>
#include <skalibs/djbunix.h>
#include <66/state.h>
#include <66/constants.h>
int state_write_tmp(ss_state_t *sta, char const *dst)
{
log_flow() ;
size_t len = strlen(dst) ;
char pack[STATE_STATE_SIZE] ;
char dir[len + SS_STATE_LEN + 1 + SS_STATUS_LEN + 1] ;
auto_strings(dir, dst, SS_STATE) ;
if (access(dir, F_OK) < 0) {
log_trace("create directory: ", dir) ;
if (!dir_create_parent(dir, 0755))
log_warnusys_return(LOG_EXIT_ZERO, "create directory: ", dir) ;
}
state_pack(pack, sta) ;
auto_strings(dir + len + SS_STATE_LEN, "/", SS_STATUS) ;
log_trace("write status file: ", dir) ;
if (!openwritenclose_unsafe(dir, pack, STATE_STATE_SIZE))
log_warnusys_return(LOG_EXIT_ZERO, "write status file: ", dir) ;
return 1 ;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment