Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
S
scom
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
SulinOS
scom
Commits
b4afeb88
Kaydet (Commit)
b4afeb88
authored
Eki 07, 2007
tarafından
S.Çağlar Onur
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
revert last merge
üst
a4e82db9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
272 additions
and
240 deletions
+272
-240
acl.h
comar/include/acl.h
+0
-1
data.h
comar/include/data.h
+0
-5
process.h
comar/include/process.h
+14
-15
utility.h
comar/include/utility.h
+4
-5
acl.c
comar/src/acl.c
+51
-43
cfg.c
comar/src/cfg.c
+2
-5
csl.c
comar/src/csl.c
+0
-7
data.c
comar/src/data.c
+0
-0
job.c
comar/src/job.c
+22
-13
log.c
comar/src/log.c
+17
-13
main.c
comar/src/main.c
+3
-2
model.c
comar/src/model.c
+55
-45
notify.c
comar/src/notify.c
+5
-4
process.c
comar/src/process.c
+27
-23
rpc_unix.c
comar/src/rpc_unix.c
+29
-24
utility.c
comar/src/utility.c
+43
-35
No files found.
comar/include/acl.h
Dosyayı görüntüle @
b4afeb88
...
...
@@ -10,7 +10,6 @@
#ifndef ACL_H
#define ACL_H 1
//! A user id and group id only
struct
Creds
{
uid_t
uid
;
gid_t
gid
;
...
...
comar/include/data.h
Dosyayı görüntüle @
b4afeb88
...
...
@@ -12,11 +12,6 @@
#include "utility.h"
//! Database operations
/*!
All database related functions are here
*/
int
db_init
(
void
);
int
db_put_script
(
int
node_no
,
const
char
*
app
,
const
char
*
buffer
,
size_t
size
);
...
...
comar/include/process.h
Dosyayı görüntüle @
b4afeb88
...
...
@@ -16,29 +16,27 @@ extern int shutdown_activated;
struct
ipc_source
{
void
*
chan
;
unsigned
int
cookie
;
/*!< To detect process */
unsigned
int
cookie
;
int
id
;
unsigned
char
lang
[
4
];
/*!< Messages language */
unsigned
char
lang
[
4
];
};
//! A basic process structure
struct
ProcChild
{
int
from
;
/*!< FIXME. */
int
to
;
/*!< FIXME. */
pid_t
pid
;
/*!< Process id */
const
char
*
desc
;
/*!< Description of process, also its name */
int
from
;
int
to
;
pid_t
pid
;
const
char
*
desc
;
// keep track of command source, used by job_cancel
struct
ipc_source
source
;
};
//! A Process
struct
Proc
{
// parent info
struct
ProcChild
parent
;
/*!< Parent of this process */
const
char
*
desc
;
/*!< Name of this process */
struct
ProcChild
parent
;
const
char
*
desc
;
// children info
int
nr_children
;
/*!< Number of children */
int
max_children
;
/*!< Maximum children */
int
nr_children
;
int
max_children
;
struct
ProcChild
*
children
;
};
...
...
@@ -47,12 +45,13 @@ struct ipc_struct {
int
node
;
};
extern
struct
Proc
my_proc
;
/*!< Per process global variable */
// per process global variable
extern
struct
Proc
my_proc
;
//
! F
or readability of send_cmd/data functions
//
f
or readability of send_cmd/data functions
#define TO_PARENT NULL
//
!
ipc commands
// ipc commands
enum
{
CMD_FINISH
=
0
,
CMD_RESULT
,
...
...
comar/include/utility.h
Dosyayı görüntüle @
b4afeb88
...
...
@@ -19,12 +19,11 @@ int utf8_is_valid(const char *str, size_t size);
unsigned
long
time_diff
(
struct
timeval
*
start
,
struct
timeval
*
end
);
//! A package struct
struct
pack
{
unsigned
char
*
buffer
;
/*!< Buffer that carries data */
size_t
max
;
/*!< Max size of data */
size_t
used
;
/*!< Used size */
unsigned
int
pos
;
/*!< Position in data */
unsigned
char
*
buffer
;
size_t
max
;
size_t
used
;
unsigned
int
pos
;
};
struct
pack
*
pack_new
(
size_t
min_size
);
...
...
comar/src/acl.c
Dosyayı görüntüle @
b4afeb88
...
...
@@ -37,11 +37,12 @@ static unsigned int acl_nr_allowed_gids;
static
int
count_groups
(
iks
*
tag
,
int
class_no
)
{
/*!
Returns the number of group tags in child tags of 'tag'
It also counts group tags under class tag ( class permissions )
@return Returns number of groups
*/
/*!
Returns the number of group tags in child tags of 'tag'
It also counts group tags under class tag ( class permissions )
@return Returns number of groups
*/
iks
*
x
;
unsigned
int
nr
=
0
;
// global permissions
...
...
@@ -62,10 +63,11 @@ count_groups(iks *tag, int class_no)
static
void
add_allowed
(
gid_t
gid
)
{
/*!
This function allocates memory for allowed group id's. @see acl_allowed_gids
Every group is added once
*/
/*!
This function allocates memory for allowed group id's. @see acl_allowed_gids
Every group is added once
*/
static
unsigned
int
max_allowed
=
0
;
unsigned
int
i
;
...
...
@@ -92,11 +94,12 @@ add_allowed(gid_t gid)
static
void
add_group
(
iks
*
tag
,
int
level
,
struct
acl_class
*
ac
)
{
/*!
Scans the 'tag's 'name' attribute, and searches the result in groups database (unix groups db)
When found, numerical group id and level is set to current group structure
\param ac is the allocated memory for acl_group structure \param level is permissions level
*/
/*!
Scans the 'tag's 'name' attribute, and searches the result in groups database (unix groups db)
When found, numerical group id and level is set to current group structure
\param ac is the allocated memory for acl_group structure \param level is permissions level
*/
struct
acl_group
*
ag
;
char
*
name
;
struct
group
*
grp
;
...
...
@@ -119,11 +122,12 @@ add_group(iks *tag, int level, struct acl_class *ac)
static
void
add_groups
(
iks
*
tag
,
int
class_no
,
int
level
,
struct
acl_class
*
ac
)
{
/*!
Searches 'tag' in 'group' and 'class' tags, calls add_group function with found tags
level and acl_class is passed to add_group
\sa add_group
*/
·
/*!
· Searches 'tag' in 'group' and 'class' tags, calls add_group function with found tags
· level and acl_class is passed to add_group
· \sa add_group
· */
iks
*
x
;
// global permissions
for
(
x
=
iks_find
(
tag
,
"group"
);
x
;
x
=
iks_next_tag
(
x
))
{
...
...
@@ -142,11 +146,12 @@ add_groups(iks *tag, int class_no, int level, struct acl_class *ac)
static
void
set_class
(
iks
*
model
,
int
class_no
)
{
/*!
Allocates memory for all found 'group's in 'model' @see count_groups()
Then add_groups is called and acl_class is put in node table
\sa add_groups
*/
·
/*!
· Allocates memory for all found 'group's in 'model' @see count_groups()
· Then add_groups is called and acl_class is put in node table
· \sa add_groups
· */
struct
acl_class
*
ac
;
int
nr_groups
=
0
;
...
...
@@ -169,10 +174,11 @@ set_class(iks *model, int class_no)
void
acl_init
(
void
)
{
/*!
Loads /etc/comar/security-policy.xml file
For all classes in model.xml file look in security-policy if theres a match
*/
·
/*!
· Loads /etc/comar/security-policy.xml file
· For all classes in model.xml file, look in security-policy if theres a match
· */
iks
*
policy
;
iks
*
model
;
int
class_no
;
...
...
@@ -205,10 +211,11 @@ acl_init(void)
static
int
check_acl
(
int
node
,
struct
Creds
*
cred
)
{
/*!
Checks if cred->uid user is capable to perform the action,
@return Returns 1 if capable, 0 otherwise
*/
·
/*!
· Checks if cred->uid user is capable to perform the action,
· @return Returns 1 if capable, 0 otherwise
· */
gid_t
gids
[
64
];
int
nr_gids
=
64
;
struct
passwd
*
pw
;
...
...
@@ -242,16 +249,16 @@ check_acl(int node, struct Creds *cred)
return
0
;
}
//! Find if user is ok to exec
cm
d
//! Find if user is ok to exec
ute comman
d
int
acl_is_capable
(
int
cmd
,
int
node
,
struct
Creds
*
cred
)
{
/*!
Checks if cred->uid user is capable executing command cmd.
Root is always capable, only CMD_CALL commands are allowed here
@return Returns 1 if allowed, 0 otherwise
*/
// root always capable
·
/*!
·
Checks if cred->uid user is capable executing command cmd.
·
Root is always capable, only CMD_CALL commands are allowed here
·
@return Returns 1 if allowed, 0 otherwise
·
*/
if
(
cred
->
uid
==
0
)
return
1
;
...
...
@@ -267,10 +274,11 @@ acl_is_capable(int cmd, int node, struct Creds *cred)
int
acl_can_connect
(
struct
Creds
*
cred
)
{
/*!
Checks if user with user id cred->uid can connect comar.
@return Returns 1 if can connect, 0 otherwise
*/
·
/*!
· Checks if user with user id cred->uid can connect comar.
· @return Returns 1 if can connect, 0 otherwise
· */
gid_t
gids
[
64
];
int
nr_gids
=
64
;
struct
passwd
*
pw
;
...
...
comar/src/cfg.c
Dosyayı görüntüle @
b4afeb88
...
...
@@ -17,7 +17,7 @@
#include "cfg.h"
#include "process.h"
/
/ global option variables with defaults
/
* global option variables with defaults */
char
*
cfg_model_file
=
"/etc/comar/model.xml"
;
char
*
cfg_data_dir
=
"/var/db/comar"
;
char
*
cfg_socket_name
=
"/var/run/comar.socket"
;
...
...
@@ -59,7 +59,7 @@ static char *shortopts = "m:d:s:g:phv";
static
void
print_usage
(
void
)
{
puts
(
puts
(
_
(
"Usage: comar [OPTIONS]
\n
"
"Pardus configuration manager.
\n
"
" -m, --model [FILE] Use the given xml model file.
\n
"
...
...
@@ -93,9 +93,6 @@ print_version(void)
void
cfg_init
(
int
argc
,
char
*
argv
[])
{
/*!
Parses command line options
*/
int
c
,
i
,
j
;
while
((
c
=
getopt_long
(
argc
,
argv
,
shortopts
,
longopts
,
&
i
))
!=
-
1
)
{
...
...
comar/src/csl.c
Dosyayı görüntüle @
b4afeb88
...
...
@@ -307,20 +307,15 @@ static PyMethodDef methods[] = {
{
NULL
,
NULL
,
0
,
NULL
}
};
//! Basic initialization
void
csl_setup
(
void
)
{
Py_Initialize
();
}
//! Log exceptions
static
void
log_exception
(
void
)
{
/*! Log exceptions as errors.
\sa log.c log_error
*/
PyObject
*
pType
;
PyObject
*
pValue
;
PyObject
*
pTrace
;
...
...
@@ -328,7 +323,6 @@ log_exception(void)
char
*
vStr
=
""
;
long
lineno
=
0
;
// Retrieve the error indicator into variables
PyErr_Fetch
(
&
pType
,
&
pValue
,
&
pTrace
);
if
(
!
pType
)
{
log_error
(
"csl.c log_exception() called when there isn't an exception
\n
"
);
...
...
@@ -508,7 +502,6 @@ csl_execute(char *code, size_t size, const char *func_name, struct pack *pak, ch
return
0
;
}
//! Finish
void
csl_cleanup
(
void
)
{
...
...
comar/src/data.c
Dosyayı görüntüle @
b4afeb88
This diff is collapsed.
Click to expand it.
comar/src/job.c
Dosyayı görüntüle @
b4afeb88
...
...
@@ -59,8 +59,11 @@ job_send_result(int cmd, const char *data, size_t size)
static
int
do_register
(
int
node
,
const
char
*
app
,
const
char
*
fname
)
{
/*! Register script by first testing it by compiling
If it compiles well, put script. \sa db_put_script csl_compile*/
·
/*!
Register script by first testing it by compiling.
· If it compiles well, put script. \sa db_put_script csl_compile
*/
char
*
buf
;
char
*
code
;
size_t
codelen
;
...
...
@@ -147,11 +150,13 @@ do_event(const char *event, int node, const char *app, struct pack *p)
static
int
do_execute
(
int
node
,
const
char
*
app
,
struct
pack
*
pak
)
{
/*! Load the app code and execute it with python/c api @see csl.c
If execution lasts more than 6 seconds, logs this information @see log_info
Returns 0 on a successfull call, returns error returned by csl execute function otherwise
\sa csl.c
*/
·
/*!
Load the app code and execute it with python/c api @see csl.c
· If execution lasts more than 6 seconds, logs this information @see log_info
· Returns 0 on a successfull call, returns error returned by csl execute function otherwise
· \sa csl.c
· */
struct
timeval
start
,
end
;
unsigned
long
msec
;
struct
pack
*
p
=
NULL
;
...
...
@@ -229,8 +234,11 @@ exec_proc(void)
static
int
do_call
(
int
node
,
struct
pack
*
pak
)
{
/*! Get scripts and run them, send results and return
@return Returns 0 */
·
/*!
Get scripts and run them, send results and return
· @return Returns 0
*/
struct
pack
*
p
=
NULL
;
char
*
apps
;
int
ok
=
0
;
...
...
@@ -354,9 +362,10 @@ do_dump_profile(void)
static
void
job_proc
(
void
)
{
/*!
Listen for incoming requests and process the commands.
*/
·
/*!
· Listen for incoming requests and process the commands.
· */
struct
ipc_struct
ipc
;
struct
pack
*
p
;
struct
ProcChild
*
sender
;
...
...
@@ -365,7 +374,7 @@ job_proc(void)
size_t
size
;
p
=
pack_new
(
256
);
// wait untill theres something to listen
// wait untill theres something to listen
while
(
1
)
{
if
(
1
==
proc_listen
(
&
sender
,
&
cmd
,
&
size
,
1
))
break
;
}
...
...
comar/src/log.c
Dosyayı görüntüle @
b4afeb88
...
...
@@ -47,10 +47,12 @@ pidstamp(FILE *f)
static
void
log_print
(
const
char
*
fmt
,
va_list
ap
,
int
error
)
{
/*! Writes log to file (cfg_log_file_name) or stdout according to cfg_log_* options
comar version, process id, timestamp and errors(if any) are written
\sa cfg.c
*/
·
/*!
Writes log to file (cfg_log_file_name) or stdout according to cfg_log_* options
· comar version, process id, timestamp and errors(if any) are written
· \sa cfg.c
· */
if
(
cfg_log_console
)
{
pidstamp
(
stdout
);
vprintf
(
fmt
,
ap
);
...
...
@@ -87,10 +89,11 @@ log_start(void)
void
log_error
(
const
char
*
fmt
,
...)
{
/*!
Same as log_info, if this function is called instead, writes
information as an 'error' to log file
*/
·
/*!
· Same as log_info, if this function is called instead, writes
· information as an 'error' to log file
· */
va_list
ap
;
va_start
(
ap
,
fmt
);
...
...
@@ -102,11 +105,12 @@ log_error(const char *fmt, ...)
void
log_info
(
const
char
*
fmt
,
...)
{
/*!
Prints log info of variable arguments with log_print function.
Console or file usage depends on cfg_log_* options
\sa log_print cfg.c
*/
·
/*!
· Prints log info of variable arguments with log_print function.
· Console or file usage depends on cfg_log_* options
· \sa log_print cfg.c
· */
va_list
ap
;
va_start
(
ap
,
fmt
);
...
...
comar/src/main.c
Dosyayı görüntüle @
b4afeb88
...
...
@@ -39,11 +39,11 @@ stop_running_comar(void)
size_t
size
;
int
sock
;
// create socket
// create socket
sock
=
socket
(
PF_LOCAL
,
SOCK_STREAM
,
0
);
if
(
sock
==
-
1
)
return
;
// a local socket
// a local socket
name
.
sun_family
=
AF_LOCAL
;
strncpy
(
name
.
sun_path
,
cfg_socket_name
,
sizeof
(
name
.
sun_path
));
size
=
(
offsetof
(
struct
sockaddr_un
,
sun_path
)
+
strlen
(
name
.
sun_path
)
+
1
);
...
...
@@ -152,5 +152,6 @@ main(int argc, char *argv[])
}
}
}
return
0
;
}
comar/src/model.c
Dosyayı görüntüle @
b4afeb88
...
...
@@ -64,10 +64,11 @@ hash_string(const unsigned char *str, int len)
static
int
prepare_tables
(
int
max_nodes
,
size_t
str_size
)
{
/*!
@return Returns 0 if successfully allocates memory for nodes, node table and paths,
-1 otherwise
*/
·
/*!
· @return Returns 0 if successfully allocates memory for nodes, node table and paths,
· -1 otherwise
· */
nodes
=
calloc
(
max_nodes
,
sizeof
(
struct
node
));
node_table
=
calloc
(
TABLE_SIZE
,
sizeof
(
struct
node
*
));
paths
=
malloc
(
str_size
);
...
...
@@ -79,10 +80,11 @@ prepare_tables(int max_nodes, size_t str_size)
static
int
add_node
(
int
parent_no
,
const
char
*
path
,
int
type
)
{
/*!
parent_no is depth of node. adds node with path and type (method)
to node table
*/
·
/*!
· parent_no is depth of node. adds node with path and type (method)
· to node table
· */
struct
node
*
n
;
int
val
;
int
len
=
strlen
(
path
);
...
...
@@ -113,11 +115,12 @@ static char *path_ptr = NULL;
static
char
*
build_path
(
iks
*
g
,
iks
*
o
,
iks
*
m
)
{
/*!
Returns the 'name' attr of 'g' iks node (group)
if 'm' is given, returns it as group.object.method (names)
if 'o' is given, returns group.object (names)
*/
·
/*!
· Returns the 'name' attr of 'g' iks node (group)
· if 'm' is given, returns it as group.object.method (names)
· if 'o' is given, returns group.object (names)
· */
if
(
path_ptr
)
{
path_ptr
+=
strlen
(
path_ptr
)
+
1
;
}
else
{
...
...
@@ -167,12 +170,13 @@ build_arg(int no, int is_instance, const char *name)
int
model_init
(
void
)
{
/*!
This function parses model.xml file (cfg_model_file)
Converts model.xml's access levels and flags to ACL levels and
flags, and loads into memory before deleting dom tree
\sa cfg.c
*/
·
/*!
· This function parses model.xml file (cfg_model_file)
· Converts model.xml's access levels and flags to ACL levels and
· flags, and loads into memory before deleting dom tree
· \sa cfg.c
· */
iks
*
model
;
iks
*
grp
,
*
obj
,
*
met
;
int
count
=
0
;
...
...
@@ -194,7 +198,6 @@ model_init(void)
}
// FIXME: ugly code ahead, split into functions and simplify
// i agree
// scan the model
for
(
grp
=
iks_first_tag
(
model
);
grp
;
grp
=
iks_next_tag
(
grp
))
{
...
...
@@ -241,7 +244,7 @@ model_init(void)
}
}
// size is counted to alloc mem for paths
// size is counted to alloc mem for paths
// prepare data structures
if
(
prepare_tables
(
count
,
size
))
return
-
1
;
...
...
@@ -332,9 +335,11 @@ model_lookup_class(const char *path)
int
model_lookup_method
(
const
char
*
path
)
{
/*! Lookup a method in node table.
@return If found, returns its number in table, returns -1 otherwise
*/
·
/*!
Lookup a method in node table.
· @return If found, returns its number in table, returns -1 otherwise·
· */
struct
node
*
n
;
int
val
;
...
...
@@ -351,10 +356,11 @@ model_lookup_method(const char *path)
int
model_lookup_notify
(
const
char
*
path
)
{
/*!
If specified path's record in node table has a type of 'notify'
returns its number in table, returns -1 otherwise
*/
·
/*!
· If specified path's record in node table has a type of 'notify'
· returns its number in table, returns -1 otherwise
· */
struct
node
*
n
;
int
val
;
...
...
@@ -371,9 +377,11 @@ model_lookup_notify(const char *path)
int
model_parent
(
int
node_no
)
{
/*! if node_no numbered record in node table is a method, returns its parent number
else returns node_no
*/
·
/*!
if node_no numbered record in node table is a method, returns its parent number
· else returns node_no
· */
struct
node
*
n
;
n
=
&
nodes
[
node_no
];
...
...
@@ -406,9 +414,10 @@ model_get_path(int node_no)
int
model_has_argument
(
int
node_no
,
const
char
*
argname
)
{
/*!
@return Returns 1 if argname is found in node table, 0 otherwise
*/
·
/*!
· @return Returns 1 if argname is found in node table, 0 otherwise
· */
struct
node
*
n
;
int
max
,
i
;
const
char
*
t
;
...
...
@@ -482,11 +491,12 @@ model_acl_set(int node_no, void *acldata)
void
model_acl_get
(
int
node_no
,
void
**
acldatap
,
unsigned
int
*
levelp
)
{
/*!
This function gets 'acldata' and 'level' from node table, from record numbered 'node_no'
\param acldatap is pointer to acldata
\param levelp is pointer to level
*/
·
/*!
· This function gets 'acldata' and 'level' from node table, from record numbered 'node_no'
· \param acldatap is pointer to acldata
· \param levelp is pointer to level
· */
struct
node
*
n
;
n
=
&
nodes
[
node_no
];
...
...
@@ -503,11 +513,12 @@ model_acl_get(int node_no, void **acldatap, unsigned int *levelp)
int
model_next_class
(
int
*
class_nop
)
{
/*!
Scans node table for class tags
@return If found, returns 1 and sets the node number to given argument (class_nop) \n
Returns 0 if no classes found
*/
·
/*!
· Scans node table for class tags
· @return If found, returns 1 and sets the node number to given argument (class_nop) \n
· Returns 0 if no classes found
· */
int
no
;
struct
node
*
n
;
...
...
@@ -523,4 +534,3 @@ model_next_class(int *class_nop)
*
class_nop
=
-
1
;
return
0
;
}
comar/src/notify.c
Dosyayı görüntüle @
b4afeb88
...
...
@@ -20,10 +20,11 @@
void
*
notify_alloc
(
void
)
{
/*!
Allocates memory for notifies and returns pointer to allocated memory
Returns Null on error.
*/
·
/*!
· Allocates memory for notifies and returns pointer to allocated memory
· Returns Null on error.
· */
int
size
;
size
=
(
model_max_notifications
+
7
)
/
8
;
...
...
comar/src/process.c
Dosyayı görüntüle @
b4afeb88
...
...
@@ -40,14 +40,14 @@ handle_signals(void)
struct
sigaction
dfl
;
act
.
sa_handler
=
handle_sigterm
;
/*! initialize and empty a signal set. Signals are to be blocked while executing handle_sigterm */
/*! initialize and empty a signal set. Signals are to be blocked while executing handle_sigterm */
sigemptyset
(
&
act
.
sa_mask
);
act
.
sa_flags
=
0
;
/*!< special flags */
ign
.
sa_handler
=
SIG_IGN
;
sigemptyset
(
&
ign
.
sa_mask
);
ign
.
sa_flags
=
0
;
dfl
.
sa_handler
=
SIG_DFL
;
/*!< default signal handling. */
sigemptyset
(
&
dfl
.
sa_mask
);
dfl
.
sa_flags
=
0
;
...
...
@@ -96,14 +96,15 @@ proc_get_rpc(void)
return
&
my_proc
.
children
[
0
];
}
//!
a
dd a child
//!
A
dd a child
static
struct
ProcChild
*
add_child
(
pid_t
pid
,
int
to
,
int
from
,
const
char
*
desc
)
{
/*!
Adds a child process with given arguments to process
@return Returns added child process
*/
·
/*!
· Adds a child process with given arguments to process
· @return Returns added child process
· */
int
i
;
i
=
my_proc
.
nr_children
;
...
...
@@ -147,10 +148,11 @@ rem_child(int nr)
static
void
stop_children
(
void
)
{
/*!
Send SIGTERM to all child processes, wait for 3 seconds
if they resist, kill'em all
*/
·
/*!
· Send SIGTERM to all child processes, wait for 3 seconds
· if they resist, kill'em all
· */
struct
timeval
start
;
struct
timeval
cur
;
struct
timeval
tv
;
...
...
@@ -227,13 +229,14 @@ proc_finish(void)
struct
ProcChild
*
proc_fork
(
void
(
*
child_func
)(
void
),
const
char
*
desc
)
{
/*!
Child process fork function, child process continues from child_func
\param desc is description, process name
@return Returns Null on error
*/
·
/*!
· Child process fork function, child process continues from child_func
· \param desc is description, process name
· @return Returns Null on error
· */
pid_t
pid
;
int
fdr
[
2
],
fdw
[
2
];
// file descriptors to read and write from pipe
int
fdr
[
2
],
fdw
[
2
];
int
i
;
pipe
(
fdr
);
...
...
@@ -241,7 +244,7 @@ proc_fork(void (*child_func)(void), const char *desc)
pid
=
fork
();
if
(
pid
==
-
1
)
return
NULL
;
if
(
pid
==
0
)
{
// child process
if
(
pid
==
0
)
{
// new child process starts
// we have to close unneeded pipes inherited from the parent
if
(
my_proc
.
parent
.
to
!=
-
1
)
close
(
my_proc
.
parent
.
to
);
...
...
@@ -307,11 +310,12 @@ proc_setup_fds(fd_set *fds)
int
proc_select_fds
(
fd_set
*
fds
,
int
max
,
struct
ProcChild
**
senderp
,
int
*
cmdp
,
size_t
*
sizep
,
int
timeout
)
{
/*!
Listen incoming requests with 'select()'
Sets command, data size and returns 1 if there's something to listen
Returns 0 otherwise
*/
·
/*!
· Listen incoming requests with 'select()'
· Sets command, data size and returns 1 if there's something to listen
· Returns 0 otherwise
· */
unsigned
int
ipc
;
struct
timeval
tv
,
*
tvptr
;
int
sock
;
...
...
comar/src/rpc_unix.c
Dosyayı görüntüle @
b4afeb88
...
...
@@ -104,24 +104,25 @@ get_size(const unsigned char *buf)
static
int
create_pipe
(
const
char
*
pipe_name
)
{
/*!
Creates a pipe, with listen. length of the queue is 5
@return Returns -2 if can't assign address to socket \n