lib/lock.c: applied MC indentation policy.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2010-10-22 15:17:27 +04:00
parent 533567c1a7
commit 8f54b9b0b5

View File

@ -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;
}