ALT Linux Team development discussions
 help / color / mirror / Atom feed
From: Vladimir Lettiev <crux@gorodmasterov.com>
To: ALT Devel discussion list <devel@altlinux.ru>
Subject: Re: [devel] Re: I: Sisyphus-20050929 unmets: +2 (93/40)
Date: Mon, 03 Oct 2005 23:03:28 +0400
Message-ID: <43418080.50905@gorodmasterov.com> (raw)
In-Reply-To: <20051003154033.GA29064@basalt.office.altlinux.org>

[-- Attachment #1: Type: text/plain, Size: 1547 bytes --]

Dmitry V. Levin пишет:
> On Sun, Oct 02, 2005 at 02:19:07PM +0400, Vladimir Lettiev wrote:
>>Я сделал патч для IPC::ShareLite.
>>Как мне показалось проблема в том, что данный модуль сначала делает 
>>shmdt() и лишь после пытается метить сегмент флагом IPC_RMID. Попробовал 
>>поменять порядок и вроде как заработало.
>>Если кто-то может его прокомментировать, welcome.

Как оказалось проблема была в том, что происходила попытка подключения к 
сегменту, который был удалён.

> Патч без контекста не очевиден, но то, что вы предлагаете сделать, логично
> и, насколько я понимаю, должно работать на всех ядрах.

Сложность в том, что IPC::ShareLite позволяет создавать сегмент, который 
может как удаляться, после отработки программы, так и нет (зачем это 
надо, не знаю). Видимо придётся фиксить также все программы, которые 
захотят использовать последнюю возможность этого модуля.

Патч я переделал. Теперь модуль проходит как собственные тесты, так и 
тесты других приложений, которые его используют (например, 
perl-Cache-Cache). Возможно ошибки всё же всплывут, но по крайне мере 
удалось исключить зависание, за счёт использования вместо semop() вызова 
semtimedop(), который позволяет задать время таймаута.

Смысл патча^Wхака в том, чтобы не детачится от сегмента, если число 
подключений меньше двух. И проверять перед унижтожением сегмента, что он 
уже не был уничтожен раньше, чтобы не нервировать shmat().

p.s. Исправленый пакет с этим патчем я уже залил в incoming.

-- 
С уважением, Владимир Леттиев aka crux <crux@gorodmasterov.com>

[-- Attachment #2: perl-IPC-ShareLite-fixOwl.patch --]
[-- Type: text/x-patch, Size: 2304 bytes --]

--- sharelite.c~~	2000-04-14 14:24:00 +0400
+++ sharelite.c	2005-10-03 22:35:59 +0400
@@ -22,12 +22,12 @@
 
 /* --- DEFINE MACROS FOR SEMAPHORE OPERATIONS --- */
 
-#define GET_EX_LOCK(A)    semop((A), &ex_lock[0],    3)
-#define GET_EX_LOCK_NB(A) semop((A), &ex_lock_nb[0], 3)
-#define RM_EX_LOCK(A)     semop((A), &ex_unlock[0],  1)
-#define GET_SH_LOCK(A)    semop((A), &sh_lock[0],    2)
-#define GET_SH_LOCK_NB(A) semop((A), &sh_lock_nb[0], 2)
-#define RM_SH_LOCK(A)     semop((A), &sh_unlock[0],  1) 
+#define GET_EX_LOCK(A)    semtimedop((A), &ex_lock[0],    3, &timeout[0])
+#define GET_EX_LOCK_NB(A) semtimedop((A), &ex_lock_nb[0], 3, &timeout[0])
+#define RM_EX_LOCK(A)     semtimedop((A), &ex_unlock[0],  1, &timeout[0])
+#define GET_SH_LOCK(A)    semtimedop((A), &sh_lock[0],    2, &timeout[0])
+#define GET_SH_LOCK_NB(A) semtimedop((A), &sh_lock_nb[0], 2, &timeout[0])
+#define RM_SH_LOCK(A)     semtimedop((A), &sh_unlock[0],  1, &timeout[0])
 
 /* --- DEFINE STRUCTURES FOR MANIPULATING SEMAPHORES --- */
 
@@ -61,6 +61,10 @@
   { 1, -1, (SEM_UNDO | IPC_NOWAIT) } /* remove shared read lock */
 };                                 
 
+static struct timespec timeout[1] = {
+  { 3, 0 } /* 3 sec timeout */
+};
+
 /* USER INITIATED LOCK */
 
 /* returns 0  on success -- requested operation performed   *
@@ -192,10 +196,14 @@
 
 int _detach_segments(Node *node) {
   Node *next_node;
+  struct shmid_ds shmarg;
 
   while(node != NULL) {
     next_node  = node->next;
-    if (shmdt((char *) node->shmaddr) < 0) return -1;
+    if (shmctl(node->shmid,IPC_STAT, &shmarg) < 0) return -1;
+    if (shmarg.shm_nattch > 1) {
+      if (shmdt((char *) node->shmaddr) < 0) return -1;
+    }
     free(node);
     node = next_node;
   }
@@ -205,12 +213,14 @@
 int _remove_segments(int shmid) {
   int    next_shmid;
   Header *shmaddr;
+  struct shmid_ds shmarg;
 
   while(shmid >= 0) {
+    if (shmctl(shmid, IPC_STAT, &shmarg) < 0 && errno == EIDRM) return 0;
     if ((shmaddr = (Header *) shmat(shmid, (char *) 0, 0)) == (Header *) -1) return -1;
     next_shmid = shmaddr->next_shmid;
-    if (shmdt((char *) shmaddr) < 0) return -1;   
     if (shmctl(shmid, IPC_RMID, (struct shmid_ds *) 0) < 0) return -1;
+    if (shmdt((char *) shmaddr) < 0) return -1;   
     shmid = next_shmid;
   }
 

      reply	other threads:[~2005-10-03 19:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-29 19:08 [devel] " Alexey M. Tourbin
2005-09-29 20:28 ` Vladimir Lettiev
2005-09-30 15:35   ` Alexey Gladkov
2005-09-30 23:15     ` Vladimir Lettiev
2005-10-01  3:16       ` [devel] " Alexey Tourbin
2005-10-01  7:16         ` Vladimir Lettiev
2005-10-01  7:28           ` Alexey Tourbin
2005-10-01 16:01           ` Dmitry V. Levin
2005-10-01 20:22             ` [devel] [JT] 2.6-ow? Michael Shigorin
2005-10-02 10:19             ` [devel] Re: I: Sisyphus-20050929 unmets: +2 (93/40) Vladimir Lettiev
2005-10-03 15:40               ` Dmitry V. Levin
2005-10-03 19:03                 ` Vladimir Lettiev [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=43418080.50905@gorodmasterov.com \
    --to=crux@gorodmasterov.com \
    --cc=devel@altlinux.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

ALT Linux Team development discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/devel/0 devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 devel devel/ http://lore.altlinux.org/devel \
		devel@altlinux.org devel@altlinux.ru devel@lists.altlinux.org devel@lists.altlinux.ru devel@linux.iplabs.ru mandrake-russian@linuxteam.iplabs.ru sisyphus@linuxteam.iplabs.ru
	public-inbox-index devel

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git