Project

General

Profile

Feature #137 » dyson-polkitunixprocess.c.patch

don't do that ;-) - Igor Pashev, 2013-06-23 10:53 AM

View differences:

policykit-1-0.105/src/polkit/polkitunixprocess.c 2013-06-23 14:44:35.778728343 +0400
33 33
#include <string.h>
34 34
#include <errno.h>
35 35
#include <stdio.h>
36
#include <fcntl.h>
37
#ifdef HAVE_SOLARIS
38
#include <procfs.h>
39
#endif
36 40

  
37 41
#include "polkitunixprocess.h"
38 42
#include "polkitsubject.h"
......
513 517
}
514 518

  
515 519
#ifdef HAVE_SOLARIS
516
static int
517
get_pid_psinfo (pid_t pid, struct psinfo *ps)
520
static gboolean
521
get_pid_psinfo (pid_t pid, psinfo_t *ps)
518 522
{
519 523
  char pname[32];
520 524
  int  procfd;
......
522 526
  (void) snprintf(pname, sizeof(pname), "/proc/%d/psinfo", pid);
523 527
  if ((procfd = open(pname, O_RDONLY)) == -1)
524 528
    {
525
      return -1;
529
      return FALSE;
526 530
    }
527
  if (read(procfd, ps, sizeof(struct psinfo)) < 0)
531
  if (read(procfd, ps, sizeof(psinfo_t)) < 0)
528 532
    {
529 533
      (void) close(procfd);
530
      return -1;
534
      return FALSE;
531 535
    }
532 536
  (void) close(procfd);
533
  return 0;
537
  return TRUE;
534 538
}
535 539
#endif
536 540

  
......
559 563
                        GError **error)
560 564
{
561 565
  guint64 start_time;
562
#ifndef HAVE_FREEBSD
566
  start_time = 0;
567
#ifdef HAVE_LINUX
563 568
  gchar *filename;
564 569
  gchar *contents;
565 570
  size_t length;
......
568 573
  gchar *p;
569 574
  gchar *endp;
570 575

  
571
  start_time = 0;
572 576
  contents = NULL;
573 577

  
574 578
  filename = g_strdup_printf ("/proc/%d/stat", pid);
......
631 635
 out:
632 636
  g_free (filename);
633 637
  g_free (contents);
634
#else
638
#elif HAVE_FREEBSD
635 639
  struct kinfo_proc p;
636 640

  
637
  start_time = 0;
638

  
639 641
  if (! get_kinfo_proc (pid, &p))
640 642
    {
641 643
      g_set_error (error,
......
650 652
  start_time = (guint64) p.ki_start.tv_sec;
651 653

  
652 654
out:
655
#elif HAVE_SOLARIS
656
  psinfo_t p;
657
  if (!get_pid_psinfo (pid, &p))
658
    {
659
      g_set_error (error,
660
                   POLKIT_ERROR,
661
                   POLKIT_ERROR_FAILED,
662
                   "Error obtaining start time for %d (%s)",
663
                   (gint) pid,
664
                   g_strerror (errno));
665
      goto out;
666
    }
667
  start_time = (guint64) p.pr_start.tv_sec;
668
out:
669
#else
670
#warning Your system is not supported
653 671
#endif
654 672

  
655 673
  return start_time;
......
660 678
                                GError            **error)
661 679
{
662 680
  gint result;
663
  gchar *contents;
664
  gchar **lines;
665 681
#ifdef HAVE_FREEBSD
666 682
  struct kinfo_proc p;
667
#else
683
#elif HAVE_LINUX
684
  gchar *contents;
685
  gchar **lines;
668 686
  gchar filename[64];
669 687
  guint n;
688
#elif HAVE_SOLARIS
689
  psinfo_t p;
690
#else
691
#warning Your system is not supported
670 692
#endif
671 693

  
672 694
  g_return_val_if_fail (POLKIT_IS_UNIX_PROCESS (process), 0);
673 695
  g_return_val_if_fail (error == NULL || *error == NULL, 0);
674 696

  
675 697
  result = 0;
676
  lines = NULL;
677
  contents = NULL;
678 698

  
679 699
#ifdef HAVE_FREEBSD
680
  if (get_kinfo_proc (process->pid, &p) == 0)
700
  if (!get_kinfo_proc (process->pid, &p))
681 701
    {
682 702
      g_set_error (error,
683 703
                   POLKIT_ERROR,
......
689 709
    }
690 710

  
691 711
  result = p.ki_uid;
692
#else
712
out:
713
#elif HAVE_SOLARIS
714
  if (!get_pid_psinfo (process->pid, &p))
715
    {
716
      g_set_error (error,
717
                   POLKIT_ERROR,
718
                   POLKIT_ERROR_FAILED,
719
                   "get_pid_psinfo() failed for pid %d: %s",
720
                   process->pid,
721
                   g_strerror (errno));
722
      goto out;
723
    }
724

  
725
  result = p.pr_uid;
726
out:
727
#elif HAVE_LINUX
728
  lines = NULL;
729
  contents = NULL;
693 730

  
694 731
  /* see 'man proc' for layout of the status file
695 732
   *
......
731 768
               POLKIT_ERROR_FAILED,
732 769
               "Didn't find any line starting with `Uid:' in file %s",
733 770
               filename);
734
#endif
735

  
736 771
out:
737 772
  g_strfreev (lines);
738 773
  g_free (contents);
774
#else
775
#warning Your system is not supported
776
#endif
777

  
739 778
  return result;
740 779
}
741 780

  
policykit-1-0.105/configure.ac 2013-06-23 11:59:07.222669274 +0400
402 402
dnl ---------------------------------------------------------------------------
403 403
case "$host_os" in
404 404
  *linux*)
405
	AC_DEFINE([HAVE_LINUX], 1, [Is this a Linux system?])
405 406
	;;
406 407
  *solaris*)
407 408
	AC_DEFINE([HAVE_SOLARIS], 1, [Is this a Solaris system?])
(2-2/3)