mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-05 11:04:42 +03:00
lib/lock.c: applied MC indentation policy.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
533567c1a7
commit
8f54b9b0b5
41
lib/lock.c
41
lib/lock.c
@ -62,7 +62,8 @@
|
|||||||
#define BUF_SIZE 255
|
#define BUF_SIZE 255
|
||||||
#define PID_BUF_SIZE 10
|
#define PID_BUF_SIZE 10
|
||||||
|
|
||||||
struct lock_s {
|
struct lock_s
|
||||||
|
{
|
||||||
char *who;
|
char *who;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
};
|
};
|
||||||
@ -79,11 +80,16 @@ lock_build_name (void)
|
|||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
|
|
||||||
pw = getpwuid (getuid ());
|
pw = getpwuid (getuid ());
|
||||||
if (pw) user = pw->pw_name;
|
if (pw)
|
||||||
if (!user) user = getenv ("USER");
|
user = pw->pw_name;
|
||||||
if (!user) user = getenv ("USERNAME");
|
if (!user)
|
||||||
if (!user) user = getenv ("LOGNAME");
|
user = getenv ("USER");
|
||||||
if (!user) user = "";
|
if (!user)
|
||||||
|
user = getenv ("USERNAME");
|
||||||
|
if (!user)
|
||||||
|
user = getenv ("LOGNAME");
|
||||||
|
if (!user)
|
||||||
|
user = "";
|
||||||
|
|
||||||
/** \todo Use FQDN, no clean interface, so requires lot of code */
|
/** \todo Use FQDN, no clean interface, so requires lot of code */
|
||||||
if (gethostname (host, BUF_SIZE - 1) == -1)
|
if (gethostname (host, BUF_SIZE - 1) == -1)
|
||||||
@ -187,17 +193,19 @@ lock_file (const char *fname)
|
|||||||
if (lockfname == NULL)
|
if (lockfname == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (lstat (lockfname, &statbuf) == 0) {
|
if (lstat (lockfname, &statbuf) == 0)
|
||||||
|
{
|
||||||
lock = lock_get_info (lockfname);
|
lock = lock_get_info (lockfname);
|
||||||
if (lock == NULL) {
|
if (lock == NULL)
|
||||||
|
{
|
||||||
g_free (lockfname);
|
g_free (lockfname);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
lockinfo = lock_extract_info (lock);
|
lockinfo = lock_extract_info (lock);
|
||||||
|
|
||||||
/* Check if locking process alive, ask user if required */
|
/* Check if locking process alive, ask user if required */
|
||||||
if (lockinfo->pid == 0
|
if (lockinfo->pid == 0 || !(kill (lockinfo->pid, 0) == -1 && errno == ESRCH))
|
||||||
|| !(kill (lockinfo->pid, 0) == -1 && errno == ESRCH)) {
|
{
|
||||||
msg =
|
msg =
|
||||||
g_strdup_printf (_
|
g_strdup_printf (_
|
||||||
("File \"%s\" is already being edited.\n"
|
("File \"%s\" is already being edited.\n"
|
||||||
@ -205,8 +213,8 @@ lock_file (const char *fname)
|
|||||||
lockinfo->who, (int) lockinfo->pid);
|
lockinfo->who, (int) lockinfo->pid);
|
||||||
/* TODO: Implement "Abort" - needs to rewind undo stack */
|
/* TODO: Implement "Abort" - needs to rewind undo stack */
|
||||||
switch (query_dialog
|
switch (query_dialog
|
||||||
(_("File locked"), msg, D_NORMAL, 2, _("&Grab lock"),
|
(_("File locked"), msg, D_NORMAL, 2, _("&Grab lock"), _("&Ignore lock")))
|
||||||
_("&Ignore lock"))) {
|
{
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
@ -249,15 +257,18 @@ unlock_file (const char *fname)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Check if lock exists */
|
/* Check if lock exists */
|
||||||
if (lstat (lockfname, &statbuf) == -1) {
|
if (lstat (lockfname, &statbuf) == -1)
|
||||||
|
{
|
||||||
g_free (lockfname);
|
g_free (lockfname);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
lock = lock_get_info (lockfname);
|
lock = lock_get_info (lockfname);
|
||||||
if (lock != NULL) {
|
if (lock != NULL)
|
||||||
|
{
|
||||||
/* Don't touch if lock is not ours */
|
/* Don't touch if lock is not ours */
|
||||||
if (lock_extract_info (lock)->pid != getpid ()) {
|
if (lock_extract_info (lock)->pid != getpid ())
|
||||||
|
{
|
||||||
g_free (lockfname);
|
g_free (lockfname);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user