mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-03 18:14:25 +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 PID_BUF_SIZE 10
|
||||
|
||||
struct lock_s {
|
||||
struct lock_s
|
||||
{
|
||||
char *who;
|
||||
pid_t pid;
|
||||
};
|
||||
@ -79,11 +80,16 @@ lock_build_name (void)
|
||||
struct passwd *pw;
|
||||
|
||||
pw = getpwuid (getuid ());
|
||||
if (pw) user = pw->pw_name;
|
||||
if (!user) user = getenv ("USER");
|
||||
if (!user) user = getenv ("USERNAME");
|
||||
if (!user) user = getenv ("LOGNAME");
|
||||
if (!user) user = "";
|
||||
if (pw)
|
||||
user = pw->pw_name;
|
||||
if (!user)
|
||||
user = getenv ("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 */
|
||||
if (gethostname (host, BUF_SIZE - 1) == -1)
|
||||
@ -187,17 +193,19 @@ lock_file (const char *fname)
|
||||
if (lockfname == NULL)
|
||||
return 0;
|
||||
|
||||
if (lstat (lockfname, &statbuf) == 0) {
|
||||
if (lstat (lockfname, &statbuf) == 0)
|
||||
{
|
||||
lock = lock_get_info (lockfname);
|
||||
if (lock == NULL) {
|
||||
if (lock == NULL)
|
||||
{
|
||||
g_free (lockfname);
|
||||
return 0;
|
||||
}
|
||||
lockinfo = lock_extract_info (lock);
|
||||
|
||||
/* Check if locking process alive, ask user if required */
|
||||
if (lockinfo->pid == 0
|
||||
|| !(kill (lockinfo->pid, 0) == -1 && errno == ESRCH)) {
|
||||
if (lockinfo->pid == 0 || !(kill (lockinfo->pid, 0) == -1 && errno == ESRCH))
|
||||
{
|
||||
msg =
|
||||
g_strdup_printf (_
|
||||
("File \"%s\" is already being edited.\n"
|
||||
@ -205,8 +213,8 @@ lock_file (const char *fname)
|
||||
lockinfo->who, (int) lockinfo->pid);
|
||||
/* TODO: Implement "Abort" - needs to rewind undo stack */
|
||||
switch (query_dialog
|
||||
(_("File locked"), msg, D_NORMAL, 2, _("&Grab lock"),
|
||||
_("&Ignore lock"))) {
|
||||
(_("File locked"), msg, D_NORMAL, 2, _("&Grab lock"), _("&Ignore lock")))
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
@ -249,15 +257,18 @@ unlock_file (const char *fname)
|
||||
return 0;
|
||||
|
||||
/* Check if lock exists */
|
||||
if (lstat (lockfname, &statbuf) == -1) {
|
||||
if (lstat (lockfname, &statbuf) == -1)
|
||||
{
|
||||
g_free (lockfname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
lock = lock_get_info (lockfname);
|
||||
if (lock != NULL) {
|
||||
if (lock != NULL)
|
||||
{
|
||||
/* 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);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user