[systemd-devel] [206] Using `systemd --user` to manage user's session -- is it still possible?

2013-08-28 Thread Ivan Shapovalov
Hello!

With systemd v204 and earlier, I used `systemd --user` to manage my complete 
session, including X server (via xorg-launch-helper) and all related things.

I used a slightly modified user-session@.service unit to start the
`systemd --user` instance in its own session to get PolicyKit working:

[Service]
PAMName=login
TTYPath=/dev/tty7 # Xorg has been configured to start on vt7

That is pretty hackish (especially the hardcoded tty) but it worked: I was 
getting an active tty session in an autologin style; the session leader was 
systemd.

With v206, that stopped working. It seems that `systemd --user` now must be 
launched
1) with PAMName=systemd-shared
2) by logind on a per-user basis
   (IOW, `systemctl start user@1000.service` does not work)

...to have it started (otherwise, `systemd --user` does not start), and

3) with /etc/pam.d/systemd-shared symlinked to system-login or whatever
   (see https://bugs.freedesktop.org/show_bug.cgi?id=68164)

...to have XDG_RUNTIME_DIR=/run/user/%U instead of /run.

With that done, systemd starts successfully, but does not get linked to any 
session (so PolicyKit does not work, audio does not work, etc).

Is it somehow possible with v206 to continue using `systemd --user` as a 
session manager?

Thanks,
- Ivan
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Convert Inittab-Entry to systemd

2013-08-28 Thread Colin Guthrie
'Twas brillig, and Daniel Spannbauer at 28/08/13 07:36 did gyre and gimble:
> Here is the service-file:
> 
> [Unit]
> Description=marco Autologin
> After=getty.target
> 
> [Service]
> ExecStart=/usr/bin/xinit /home/xalz/.xsession -- /usr/bin/X :1 vt08 -r
> -br -dpms -s off
> User=xalz
> PAMName=xalz
  

Use literally: "PAMName=login"

When Auke made his earlier comments he was being literal but I can see
how it could be interpreted to mean "use *your* login name" :)

It corresponds to the file in /etc/pam.d/login which controls how things
in the PAM stack are initialised are initialised.

HTHs

Col

> Group=alz
> Environment="PATH=/usr/uti/sys:/usr/uti:/usr/uti/mcu::/usr/uti/sys:/usr/uti:/usr/uti/mcu:/sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/usr/uti/inst:/usr/uti/inst"
> 
> [Install]
> WantedBy=multi-user.target
> 
> 
> any ideas?


-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited http://www.tribalogic.net/
Open Source:
  Mageia Contributor http://www.mageia.org/
  PulseAudio Hacker http://www.pulseaudio.org/
  Trac Hacker http://trac.edgewall.org/
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] implies "MemoryAccounting=true"

2013-08-28 Thread Zbigniew Jędrzejewski-Szmek
On Mon, Aug 26, 2013 at 11:19:54AM +0800, Gao feng wrote:
> Hi
> 
> The SYSTEMD.CGROUP(5) said if MemoryLimit=bytes is set for unit, it
> implies MemeoryAccounting=true for this unit.
> 
> But seems systemd didn't implement this hint. CPUShares & BlockIO have
> the same problem, this is a shortage? patch needed?
Hm, without looking at code actually, I thought that this
is basically a limitation/requirement of the cgroup controller:
if a memory share is assigned, memory accounting will be performed
by the kernelfor it to work.

Zbyszek
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] blcokio bandwidth: add missing set of CGroupBlockIODeviceBandwidth's read

2013-08-28 Thread Zbigniew Jędrzejewski-Szmek
On Wed, Aug 28, 2013 at 12:10:16PM +0800, Gao feng wrote:
> BlockIOReadBandwidth and BlockIOWriteBandwidth both use
> config_parse_blockio_bandwidth to set up CGroupBlockIODeviceBandwidth,
> We should set the read value based on the left values
> in config files.
Applied.

Zbyszek
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH v2] device cgroup: don't create a new CGroupDeviceAllow when it already in the list

2013-08-28 Thread Zbigniew Jędrzejewski-Szmek
On Wed, Aug 28, 2013 at 09:49:11AM +0800, Gao feng wrote:
> If a device node is already in the device_allow list of
> CGroupContext, we should replace it instead of create a
> new one and append this new one to the end of device_allow
> list.
> 
> change from v1: use streq to replace !strcmp
Applied.

Zbyszek
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] cgroup: only check once when mode is UNIT_CHECK

2013-08-28 Thread Zbigniew Jędrzejewski-Szmek
On Mon, Aug 26, 2013 at 10:36:45AM +0800, Gao feng wrote:
> If the mode is UNIT_CHECK,it means we only want to check if
> the paramaters are valid. the first round of cycle already
> did this check, no need to check again.
Applied.

Zbyszek
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [206] Using `systemd --user` to manage user's session -- is it still possible?

2013-08-28 Thread Mantas Mikulėnas
Partial reply:

On Wed, Aug 28, 2013 at 10:15 AM, Ivan Shapovalov  wrote:
> With v206, that stopped working. It seems that `systemd --user` now must be
> launched
> 1) with PAMName=systemd-shared
> […]
> 3) with /etc/pam.d/systemd-shared symlinked to system-login or whatever
>(see https://bugs.freedesktop.org/show_bug.cgi?id=68164)
>
> ...to have XDG_RUNTIME_DIR=/run/user/%U instead of /run.

The only requirement here is that PAM must call pam_systemd.so to set
up cgroups and XDG_RUNTIME_DIR. It's nothing new to v205/v206.

> 2) by logind on a per-user basis
>(IOW, `systemctl start user@1000.service` does not work)

It /should/ work, because that's exactly how logind starts it.

-- 
Mantas Mikulėnas 
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Fedora 19 hangs on startup: A start job is running for Monitoring of LVM2 mirror...rogress polling

2013-08-28 Thread Zbigniew Jędrzejewski-Szmek
On Thu, Aug 22, 2013 at 09:07:09AM -0700, Ben Greear wrote:
> I have a E5 processor system with 128GB SSD freshly installed and updated
> with Fedora 19.  After the initial boot, I added MATE, put system at runlevel 
> 3,
> removed 'initial-setup' package, and so forth.  System is
> configured for serial console.  I'm not sure how much of this matters, 
> however.
> 
> On bootup, the system hung with the error:
> 
> "A start job is running for Monitoring of LVM2 mirror...rogress polling"
> 
> The little red stars move back and forth, so not a total cpu lock,
> but it made no progress in this state overnight.
Seems like an outright systemd bug, if you're not thrown into a rescue
session at some point. Can you pull the logs from this boot? (From the
options in http://freedesktop.org/wiki/Software/systemd/Debugging/,
systemd.log_level=debug and debug-shell.service are probably most
useful).

Zbyszek

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] service: remove pidfile after exit of a service

2013-08-28 Thread Lukas Nykryn
---
 TODO   | 2 --
 src/core/service.c | 4 
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/TODO b/TODO
index fe305ec..3527970 100644
--- a/TODO
+++ b/TODO
@@ -60,8 +60,6 @@ Features:
 
 * better error message if you run systemctl without systemd running
 
-* unlink PID files of units after exit
-
 * tiny tool that saves/restores backlight
 
 * systemctl status output should should include list of triggering units and 
their status
diff --git a/src/core/service.c b/src/core/service.c
index 4070fd7..916821f 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -1957,6 +1957,10 @@ static void service_enter_dead(Service *s, ServiceResult 
f, bool allow_restart)
 /* we want fresh tmpdirs in case service is started again immediately 
*/
 exec_context_tmp_dirs_done(&s->exec_context);
 
+/* try to delete pidfile*/
+if (s->pid_file)
+unlink_noerrno(s->pid_file);
+
 return;
 
 fail:
-- 
1.8.3.1

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] util: ellipsize_mem: do not print partial utf-8 characters

2013-08-28 Thread Shawn Landden
---
 src/shared/util.c | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/shared/util.c b/src/shared/util.c
index 1dde8af..9af99aa 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -3286,7 +3286,7 @@ int running_in_chroot(void) {
 }
 
 char *ellipsize_mem(const char *s, size_t old_length, size_t new_length, 
unsigned percent) {
-size_t x;
+size_t x, j;
 char *r;
 
 assert(s);
@@ -3305,13 +3305,20 @@ char *ellipsize_mem(const char *s, size_t old_length, 
size_t new_length, unsigne
 if (x > new_length - 3)
 x = new_length - 3;
 
+for (;s[x-1] > 127;x--)
+continue;
+
 memcpy(r, s, x);
 r[x] = '.';
 r[x+1] = '.';
 r[x+2] = '.';
+
+for (j=(x+3);s[j] > 127;j++)
+continue;
+
 memcpy(r + x + 3,
-   s + old_length - (new_length - x - 3),
-   new_length - x - 3);
+   s + old_length - (new_length - j),
+   new_length - j);
 
 return r;
 }
-- 
1.8.4.rc3

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH resend] getty-generator: Enable getty on all active serial consoles.

2013-08-28 Thread Michael Marineau
This enables a getty on active kernel consoles even when they are not
the last one specified on the kernel command line and mapped to
/dev/console. Now the order "console=ttyS0 console=tty0" works in
addition to "console=tty0 console=ttyS0".
---
 src/getty-generator/getty-generator.c | 37 ++-
 1 file changed, 23 insertions(+), 14 deletions(-)

diff --git a/src/getty-generator/getty-generator.c 
b/src/getty-generator/getty-generator.c
index 4b7a60a..6c93806 100644
--- a/src/getty-generator/getty-generator.c
+++ b/src/getty-generator/getty-generator.c
@@ -122,33 +122,42 @@ int main(int argc, char *argv[]) {
 }
 
 if (read_one_line_file("/sys/class/tty/console/active", &active) >= 0) 
{
-const char *tty;
-
-tty = strrchr(active, ' ');
-if (tty)
-tty ++;
-else
-tty = active;
-
-/* Automatically add in a serial getty on the kernel
- * console */
-if (isempty(tty) || tty_is_vc(tty))
-free(active);
-else {
+char *w, *state;
+size_t l;
+
+/* Automatically add in a serial getty on all active
+ * kernel consoles */
+FOREACH_WORD(w, l, active, state) {
+char *tty;
 int k;
 
+tty = strndup(w, l);
+if (!tty) {
+log_oom();
+free(active);
+r = EXIT_FAILURE;
+goto finish;
+}
+
+if (isempty(tty) || tty_is_vc(tty)) {
+free(tty);
+continue;
+}
+
 /* We assume that gettys on virtual terminals are
  * started via manual configuration and do this magic
  * only for non-VC terminals. */
 
 k = add_serial_getty(tty);
-free(active);
 
 if (k < 0) {
+free(tty);
+free(active);
 r = EXIT_FAILURE;
 goto finish;
 }
 }
+free(active);
 }
 
 /* Automatically add in a serial getty on the first
-- 
1.8.1.5

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] util: ellipsize_mem: do not print partial utf-8 characters

2013-08-28 Thread Zbigniew Jędrzejewski-Szmek
On Wed, Aug 28, 2013 at 12:36:10PM -0700, Shawn Landden wrote:
> ---
>  src/shared/util.c | 13 ++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/src/shared/util.c b/src/shared/util.c
> index 1dde8af..9af99aa 100644
> --- a/src/shared/util.c
> +++ b/src/shared/util.c
> @@ -3286,7 +3286,7 @@ int running_in_chroot(void) {
>  }
>  
>  char *ellipsize_mem(const char *s, size_t old_length, size_t new_length, 
> unsigned percent) {
> -size_t x;
> +size_t x, j;
>  char *r;
>  
>  assert(s);
> @@ -3305,13 +3305,20 @@ char *ellipsize_mem(const char *s, size_t old_length, 
> size_t new_length, unsigne
>  if (x > new_length - 3)
>  x = new_length - 3;
>  
> +for (;s[x-1] > 127;x--)
> +continue;
> +
>  memcpy(r, s, x);
>  r[x] = '.';
>  r[x+1] = '.';
>  r[x+2] = '.';
> +
> +for (j=(x+3);s[j] > 127;j++)
> +continue;
> +
>  memcpy(r + x + 3,
> -   s + old_length - (new_length - x - 3),
> -   new_length - x - 3);
> +   s + old_length - (new_length - j),
> +   new_length - j);

That's a good step, but we should also calculate new_length properly, counting
characters not bytes. Just counting unicode units, without looking for combining
characters or anything like this should be enough imho.

Zbyszek
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] util, utf8: new wellipsize and wellipsize_mem that take into account multi-byte characters

2013-08-28 Thread Shawn Landden
This version counts all multibyte characters as 1 width, not taking into
account double width cjk characters and zerowidth characters
---
 TODO  |  4 ---
 src/shared/utf8.c | 56 +++
 src/shared/utf8.h | 98 +++
 src/shared/util.c | 55 +++
 src/shared/util.h |  2 ++
 5 files changed, 211 insertions(+), 4 deletions(-)

diff --git a/TODO b/TODO
index fe305ec..a77ebe5 100644
--- a/TODO
+++ b/TODO
@@ -19,10 +19,6 @@ Bugfixes:
 
 * properly handle .mount unit state tracking when two mount points are stacked 
one on top of another on the exact same mount point.
 
-* ellipsize_mem must take into account multi-byte unicode characters, and
-  - make the resulting line the requested number of *characters*, not *bytes*,
-  - avoid truncuating multi-byte sequences in the middle.
-
 * When we detect invalid UTF-8, we cant't use it in an error message:
   log...("Path is not UTF-8 clean, ignoring assignment: %s", rvalue);
 
diff --git a/src/shared/utf8.c b/src/shared/utf8.c
index 655cc77..8a37c3a 100644
--- a/src/shared/utf8.c
+++ b/src/shared/utf8.c
@@ -22,6 +22,11 @@
 /* This file is based on the GLIB utf8 validation functions. The
  * original license text follows. */
 
+/* gunicode.h - Unicode manipulation functions
+ *
+ *  Copyright (C) 1999, 2000 Tom Tromey
+ *  Copyright 2000, 2005 Red Hat, Inc.
+ */
 /* gutf8.c - Operations on UTF-8 strings.
  *
  * Copyright (C) 1999 Tom Tromey
@@ -317,3 +322,54 @@ char *utf16_to_utf8(const void *s, size_t length) {
 
 return r;
 }
+
+/**
+ * g_utf8_prev_char:
+ * @p: a pointer to a position within a UTF-8 encoded string
+ *
+ * Finds the previous UTF-8 character in the string before @p.
+ *
+ * @p does not have to be at the beginning of a UTF-8 character. No check
+ * is made to see if the character found is actually valid other than
+ * it starts with an appropriate byte. If @p might be the first
+ * character of the string, you must use g_utf8_find_prev_char() instead.
+ *
+ * Return value: a pointer to the found character.
+ **/
+char *
+utf8_prev_char (const char *p)
+{
+  while (1)
+{
+  p--;
+  if ((*p & 0xc0) != 0x80)
+   return (char *)p;
+}
+}
+
+/**
+ * g_utf8_get_char:
+ * @p: a pointer to Unicode character encoded as UTF-8
+ *
+ * Converts a sequence of bytes encoded as UTF-8 to a Unicode character.
+ * If @p does not point to a valid UTF-8 encoded character, results are
+ * undefined. If you are not sure that the bytes are complete
+ * valid Unicode characters, you should use g_utf8_get_char_validated()
+ * instead.
+ *
+ * Return value: the resulting character
+ **/
+unichar
+utf8_get_char (const char *p)
+{
+  int i, mask = 0, len;
+  unichar result;
+  unsigned char c = (unsigned char) *p;
+
+  UTF8_COMPUTE (c, mask, len);
+  if (len == -1)
+return (unichar)-1;
+  UTF8_GET (result, p, i, mask, len);
+
+  return result;
+}
\ No newline at end of file
diff --git a/src/shared/utf8.h b/src/shared/utf8.h
index f805ea6..020bc27 100644
--- a/src/shared/utf8.h
+++ b/src/shared/utf8.h
@@ -34,3 +34,101 @@ char *utf8_filter(const char *s);
 char *ascii_filter(const char *s);
 
 char *utf16_to_utf8(const void *s, size_t length);
+
+#define unichar uint32_t
+
+char *utf8_prev_char (const char *p);
+unichar utf8_get_char (const char *p);
+
+#define UTF8_COMPUTE(Char, Mask, Len)\
+  if (Char < 128)\
+{\
+  Len = 1;   \
+  Mask = 0x7f;   \
+}\
+  else if ((Char & 0xe0) == 0xc0)\
+{\
+  Len = 2;   \
+  Mask = 0x1f;   \
+}\
+  else if ((Char & 0xf0) == 0xe0)\
+{\
+  Len = 3;   \
+  Mask = 0x0f;   \
+}\
+  else if ((Char & 0xf8) == 0xf0)\
+{\
+  Len = 4;   \
+  Mask = 0x07;   \
+}

[systemd-devel] [PATCH] util, utf8: recognize wide characters in wellipsize_mem()

2013-08-28 Thread Shawn Landden
---
 src/shared/utf8.c | 64 +++
 src/shared/utf8.h |  4 +++-
 src/shared/util.c | 19 ++---
 src/shared/util.h |  1 +
 4 files changed, 84 insertions(+), 4 deletions(-)

diff --git a/src/shared/utf8.c b/src/shared/utf8.c
index 8a37c3a..607f0c1 100644
--- a/src/shared/utf8.c
+++ b/src/shared/utf8.c
@@ -372,4 +372,68 @@ utf8_get_char (const char *p)
   UTF8_GET (result, p, i, mask, len);
 
   return result;
+}
+
+struct Interval
+{
+  unichar start, end;
+};
+
+static int
+interval_compare (const void *key, const void *elt)
+{
+  unichar c = (unichar) (long) (key);
+  struct Interval *interval = (struct Interval *)elt;
+
+  if (c < interval->start)
+return -1;
+  if (c > interval->end)
+return +1;
+
+  return 0;
+}
+
+/*
+ * NOTE:
+ *
+ * The tables for g_unichar_iswide() and g_unichar_iswide_cjk() are
+ * generated from the Unicode Character Database's file
+ * extracted/DerivedEastAsianWidth.txt using the gen-iswide-table.py
+ * in this way:
+ *
+ *   ./gen-iswide-table.py < path/to/ucd/extracted/DerivedEastAsianWidth.txt | 
fmt
+ *
+ * Last update for Unicode 6.0.
+ */
+
+/**
+ * g_unichar_iswide:
+ * @c: a Unicode character
+ *
+ * Determines if a character is typically rendered in a double-width
+ * cell.
+ *
+ * Return value: %TRUE if the character is wide
+ **/
+bool
+unichar_iswide (unichar c)
+{
+  /* See NOTE earlier for how to update this table. */
+  static const struct Interval wide[] = {
+{0x1100, 0x115F}, {0x2329, 0x232A}, {0x2E80, 0x2E99}, {0x2E9B, 0x2EF3},
+{0x2F00, 0x2FD5}, {0x2FF0, 0x2FFB}, {0x3000, 0x303E}, {0x3041, 0x3096},
+{0x3099, 0x30FF}, {0x3105, 0x312D}, {0x3131, 0x318E}, {0x3190, 0x31BA},
+{0x31C0, 0x31E3}, {0x31F0, 0x321E}, {0x3220, 0x3247}, {0x3250, 0x32FE},
+{0x3300, 0x4DBF}, {0x4E00, 0xA48C}, {0xA490, 0xA4C6}, {0xA960, 0xA97C},
+{0xAC00, 0xD7A3}, {0xF900, 0xFAFF}, {0xFE10, 0xFE19}, {0xFE30, 0xFE52},
+{0xFE54, 0xFE66}, {0xFE68, 0xFE6B}, {0xFF01, 0xFF60}, {0xFFE0, 0xFFE6},
+{0x1B000, 0x1B001}, {0x1F200, 0x1F202}, {0x1F210, 0x1F23A}, {0x1F240,
+0x1F248}, {0x1F250, 0x1F251}, {0x2, 0x2FFFD}, {0x3, 0x3FFFD}
+  };
+
+  if (bsearch ((long)c, wide, (sizeof (wide) / sizeof ((wide)[0])), sizeof 
wide[0],
+  interval_compare))
+return true;
+
+  return false;
 }
\ No newline at end of file
diff --git a/src/shared/utf8.h b/src/shared/utf8.h
index 020bc27..f1be180 100644
--- a/src/shared/utf8.h
+++ b/src/shared/utf8.h
@@ -131,4 +131,6 @@ static const char utf8_skip_data[256] = {
  * Before using this macro, use g_utf8_validate() to validate strings
  * that may contain invalid UTF-8.
  */
-#define utf8_next_char(p) (char *)((p) + utf8_skip_data[*(const char *)(p)])
\ No newline at end of file
+#define utf8_next_char(p) (char *)((p) + utf8_skip_data[*(const char *)(p)])
+
+bool unichar_iswide (unichar c);
\ No newline at end of file
diff --git a/src/shared/util.c b/src/shared/util.c
index 58a1787..1c73b3e 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -3357,22 +3357,35 @@ char *wellipsize_mem(const char *s, size_t old_length, 
size_t new_length, unsign
 if (x > new_length - 3)
 x = new_length - 3;
 
-for (i = (char *)s;k < x;i = utf8_next_char(i))
+for (i = (char *)s;k < x;i = utf8_next_char(i)) {
+c = utf8_get_char(i);
 k++;
+if (unichar_iswide(c))
+k++;
+}
+
+if (k > x) /* last character was wide and went over quota */
+x++;
 
 j = i - s;
 memcpy(e, s, j);
-e[j] = '.';   /* TODO: use … tri-dot? */
-e[j+1] = '.'; /* 0xe2 0x80 0xa6 */
+e[j]   = '.'; /* TODO: use … tri-dot? */
+e[j+1] = '.'; /* 0xE2 0x80 0xA6 */
 e[j+2] = '.';
 
 k = 0;
 for (i = (char *)s + old_length;
  k < new_length - x - 3;) {
 i = utf8_prev_char(i);
+c = utf8_get_char(i);
 k++;
+if (unichar_iswide(c))
+k++;
 }
 
+if (k > new_length - x - 3) /* last (reverse) character was wide and 
went over quota */
+i = utf8_next_char(i);
+
 strcpy(e + j + 3, i);
 
 return e;
diff --git a/src/shared/util.h b/src/shared/util.h
index 9b17db9..97d8697 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -405,6 +405,7 @@ int running_in_chroot(void);
 char *ellipsize(const char *s, size_t length, unsigned percent);
 char *ellipsize_mem(const char *s, size_t old_length, size_t new_length, 
unsigned percent);
 char *wellipsize(const char *s, size_t length, unsigned percent);
+/* bytes  columns */
 char *wellipsize_mem(const char *s, size_t old_length, size_t new_length, 
unsigned percent);
 
 int touch(const char *path);
-- 
1.8.4.rc3

___
system

Re: [systemd-devel] [PATCH] util, utf8: recognize wide characters in wellipsize_mem()

2013-08-28 Thread Shawn
here is the test runner I am using, doesn't really make sense to add this
to the tree as it has to be visually inspected

diff --git a/Makefile.am b/Makefile.am
index cdbfdea..8813299 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1124,6 +1124,7 @@ tests += \
test-unit-file \
test-util \
test-date \
+   test-wellipsize \
test-sleep \
test-replace-var \
test-sched-prio \
@@ -1302,6 +1303,12 @@ test_date_SOURCES = \
 test_date_LDADD = \
libsystemd-core.la

+test_wellipsize_SOURCES = \
+src/test/test-wellipsize.c
+
+test_wellipsize_LDADD = \
+libsystemd-core.la
+
 test_sleep_SOURCES = \
src/test/test-sleep.c
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/

/***
  This file is part of systemd.

  Copyright 2012 Lennart Poettering

  systemd is free software; you can redistribute it and/or modify it
  under the terms of the GNU Lesser General Public License as published by
  the Free Software Foundation; either version 2.1 of the License, or
  (at your option) any later version.

  systemd is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public License
  along with systemd; If not, see .
***/

#include 

#include "util.h"
#include "utf8.h"

static void test_one(const char *p) {
puts(wellipsize(p, 80, 70));
}

int main(int argc, char *argv[]) {
test_one("s한국어한국어한국어한국어한국어한국어한국어한국어한국어한국어한국어한국어한국어한국어한국어한국어한국어한국어");
test_one("日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国");
test_one("€€");
test_one("………");
test_one("🐮🐮🐮");
test_one("asdfnjaskdfnklasdgnjaskdghnkasdgfklasdfjkasdfjaksdfaskldfnaskldfnaskldfnaklsdfnaklsdfnklnaskjgdknl");

return 0;
}
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel